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

masih1f's avatar

SPA and Mobile Logout

how to delete token related to SPA or Mobile in logout route? i used sanctum with this $user->currentAccessToken()->delete(); in the logout action but i got this error "Call to undefined method Laravel\Sanctum\TransientToken::delete()" i know it relates to EnsureFrontendRequestsAreStateful middleware but i want to use SPA and mobile at the same time. $user->tokens()->delete() work but it deletes all user tokens.

another question i have: can i use sanctum access token as public key for third party authentication in our API system. i want to create token for user in the admin panel and with this token user can use API of our system.

0 likes
6 replies
jlrdw's avatar

At some place try:

Auth::user()->tokens()->where('id', $id)->delete();

Passing in the user id to logout should work. But don't know your setup.

masih1f's avatar

it delete all tokens, i want to delete just current access token. assume a user login with web browser or mobile app or try to use API as third party in this way all tokens deleted

masih1f's avatar

Thanks but i tried earlier and it dosen't work, throw an error {"message":"Call to undefined method Laravel\Sanctum\TransientToken::delete()","errors":null

jlrdw's avatar

@masih1f previous answer is from documentation. Check your setup and see what you might be missing.

It's hard to tell since we don't know all your code. Also read over the documentation again to see if you missed something.

Edit: this series https://laracasts.com/series/laravel-authentication-options

Also has a few videos covering API and sanctum, and mobile. Usually the code is also available on GitHub.

masih1f's avatar

i have this issue see it: github .com/laravel/sanctum/issues/48#issuecomment-747533603

Please or to participate in this conversation.