I have an external API which handles the authentication and returns the token in which i store it in the session. However whenever i log out and remove the session, the blade file doesn't update the session till i refresh the page.
Below is how i save the authentication state when user has logged in and logged out
// User logged in
$request->session()->put('authenticated', true);
$request->session()->put('token', $data->response->token);
$request->session()->put('user', $data->response->user);
$request->session()->save();
// User logged out
$request->session()->put('authenticated', false);
$request->session()->forget(['token', 'user']);
$request->session()->save();
Whenever the user has logged out my blade file still detects the authenticated session and renders as it the user is still logged in
@if (session('authenticated'))
<header-auth-block :is_login="true" class="ml-lg-3"></header-auth-block>
@else
<header-auth-block :is_login="false" class="ml-lg-3"></header-auth-block>
@endif
Anyone able to assist me on this? Or is there an alternative to saving the user authentication state.
EDIT
My logout function is called from Vue and the window would redirect back to login page. I suspect that when the user is redirected via VueJS, the session doesn't get updated or it doesn't fetch a new request from the server.
async sendLogoutAPI(){
axios.post('/auth/logout').then((response) => {
if(response.status == 200){
window.location.href = '/auth/login'
}
}).catch(error => {
console.log(error);
})
}