You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After logging out and i dont refresh the browser sanctum still logs me in
i have a laravel api and react front end
Steps To Reproduce
This is my log out in laravel api ive tried all solutions they have failed thats why u see many comments there
public function logout(Request $request)
{
/** @var \App\Models\User */
$user = Auth::user(); // Get the authenticated user
$userToken = $user->token();
$userToken->revoke();
// // // Delete all tokens for the user
// // $user->tokens()->delete();
// // delete the current token that was used for the request
// $request->user()->currentAccessToken()->delete();
// //
// session()->flush();
// Auth::logout();
// $request->session()->invalidate();
// $request->session()->regenerateToken();
return response()->json(['message' => 'Logged out successfully']);
}
react
uill see in my react i had to first reload the browser which isnt cool
window.location.reload();
// Logout mutation function
const logoutMutation = useMutation({
mutationFn: logout,
onSuccess: (data) => {
setLogoutMutationIsLoading(false);
// clear local storage
// localStorage.removeItem("access_token");
// localStorage.removeItem("refresh_token");
// Set localStorage items to null
// localStorage.setItem("access_token", "null");
// localStorage.setItem("refresh_token", "null");
localStorage.removeItem("access_token");
localStorage.removeItem("refresh_token");
// Reset the user state to null
queryClient.resetQueries();
queryClient.clear();
queryClient.refetchQueries();
// Remove the Authorization header from Axios
axios.defaults.headers.common["Authorization"] = null;
// Remove the Authorization header from Axios
delete axios.defaults.headers.common["Authorization"];
// Set loading state to false
console.log("logout response is : ", data);
navigate("/login");
window.location.reload();
// Display a success toast message
toast.success("Goodbye 👋");
},
onError: (error) => {
setLogoutMutationIsLoading(false);
// Display an error toast message
toast.error("Logout Error");
// Log the error
console.log("Logout errors ", error);
},
});
The text was updated successfully, but these errors were encountered:
bloodykheeng
changed the title
Sanctum still logs in after deleting tokens & you dont refresh browser
Sanctum still logs in after logging out & deleting tokens in a scenario where you dont refresh browser
Oct 30, 2024
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?
Sanctum Version
4.0
Laravel Version
11.0
PHP Version
8.2
Database Driver & Version
No response
Description
After logging out and i dont refresh the browser sanctum still logs me in
i have a laravel api and react front end
Steps To Reproduce
This is my log out in laravel api ive tried all solutions they have failed thats why u see many comments there
react
uill see in my react i had to first reload the browser which isnt cool
window.location.reload();
The text was updated successfully, but these errors were encountered: