Reputation: 2198
Maybe is stupid question but is possible to check is user logged in with javascript...
How to check is user logged in with JavaScript?
I tried:
$(document).ready(function() {
$('#facebook').click(function(){
window.open(this.href, "myWindowName", "width=800, height=600");
return false;
setInterval(function() {
@if {{Auth::check()}};
alert('loged')
@else
alert('not loged')
@endif
}, 5000);
});
});
of course this doesn't work.
So I need when I click on #facebook
to check every 5 seconds if user is logged in.
Upvotes: 2
Views: 2402
Reputation: 1290
Send ajax request to a route some like http://example.com/auth/check
and return true/false from this route.
Route::get('/auth/check',function(){
return (\Auth::check()) ? True : False
});
Or you can return some formatted JSON.
Upvotes: 4