Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Joob's avatar
Level 1

logout destroy

Hello,

My logout is not 100%, it seems that sometimes when I logout, it refreshes and goes back to where it was instead of logging out, it doesn't seem to delete the token.

  class DestroyActiveBearerTokenController extends Controller 
   {
        public function __invoke(): JsonResponse
      {
    [$id, $token] = explode('|', request()->bearerToken(), 2);

    // Get token
    $instance = PersonalAccessToken::findOrFail($id);

    // Check the correct token
    if (hash_equals($instance->token, hash('sha256', $token))) {
        // Delete token
        $instance->delete();

        return response()->json([
            'type'    => 'success',
            'message' => 'You were successfully logged out',
        ]);
    }

    return response()->json([
        'type'    => 'error',
        'message' => 'You are not authorized',
    ], 401);
}
}

In vue I use this

 logOut() {
        this.$store.dispatch('logOut')
    },

Thank you

0 likes
0 replies

Please or to participate in this conversation.