@mjk22071998 You don’t “log out” of an API. If you want to “log out” a user from a native application then invalidate or revoke their active token.
Laravel Sanctum: Best Practices for Logout in Mobile Apps
Hello Laravel experts,
I hope you are all doing well. I am using Laravel Sanctum for authentication while working on the backend of a mobile application. However, I am facing an issue with the logout route. I have applied the auth:sanctum middleware to it, but on the mobile application side, there are some issues where the token either gets changed or is deleted from shared preferences, making it difficult to call the logout API.
What are the best practices in this scenario? Should the token management be handled on the mobile application side, or would it be better to remove the auth:sanctum middleware from the logout route? I would appreciate any insights or recommendations.
Thank you!
@mjk22071998 If the token is “lost” then the user is no longer authenticated, so send them back to through the authentication flow to get a fresh token.
Please or to participate in this conversation.