User Logout - Laravel

User Logout - Laravel

This example shows how you can implement user logout on the server side using the DID Token.

The example assumes:

important

It is important to always validate the DID Token before using.

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Magic; class UserController extends Controller { function logout(Request $request){ $did_token = $request->bearerToken(); if ($did_token == null) { // DIDT is missing from the original HTTP request header. // You can handle this by remapping it to your application error. } try { // Validate the did token Magic::token()->validate($did_token); $issuer = Magic::token()->get_issuer($did_token); } catch (Throwable $e) { // DIDT is malformed. // You can handle this by remapping it to your application error. report($e); return false; } if ($user_info->issuer != $issuer) { // Unauthorized login due to issuer mismatch.You can handle this by remapping // it to your application error. } try { Magic::user()->logout_by_issuer($issuer); } catch (Throwable $e) { // HTTP error. You can handle this by remapping it to your application error. report($e); return false; } // Any other cleanup from your application. Ex: expunge user cookies. } }
User Logout - Laravel