Do I need to clear local storage on the frontend if my laravel controller logout() is handling the logging out of a user?
I have a function in my controller that's supposed to log a user out. It returns a success message upon clicking Logout on the frontend. My question is, on the JS side, do I need to clear local storage?
I'm asking this because upon refreshing my page after a successful logout and landing on the login screen (when logging out, the user gets redirected from the dashboard to the login screen) - I get sent back to dashboard which to me indicates that my logout function isn't working as intended (or is it?).
Am I doing something wrong?
Here's my controller code:
public function logout(Request $request) {
try {
$this->_usersRepository->userLogout();
$loggedOut = $this->_usersRepository->userLogout()->getStatusCode();
if($loggedOut != 200) {
return response()->json(['message' => 'Error while logging out!'], 500);
}
return response()->json([
'message' => 'Successfully logged out',
'loggedOut' => $loggedOut
]);
} catch (\Exception $e) {
Log::error($e->getMessage());
throw new \Exception($e->getMessage(), $e->getCode(), $e);
}
}
Respository code for deleting oauth_access_tokens
in the DB:
public function userLogout() {
DB::table('oauth_access_tokens')->where('user_id', Auth::id())->delete();
return response()->json(['message' => 'User successfully signed out'], 200);
}
source https://stackoverflow.com/questions/68966884/do-i-need-to-clear-local-storage-on-the-frontend-if-my-laravel-controller-logout
Comments
Post a Comment