Support the ongoing development of Laravel.io →
Authentication Architecture Jobs
Last updated 1 year ago.
0

you can track him using js, for example when the user leaves the page or closes the browser, with js you can trigger an ajax call when this happens

to do this you must listen to onunload event, with jquery its implementation is super easy

$( window ).on( 'unload', function() {
    $.ajax( '/user/is-leaving' );
} );

note that you not need to listen a sucess ajax event, just send the request to the server

Last updated 1 year ago.
0

So I'm hoping this thread will help others out there as well as myself. I also took a look into using event listerns so I found this :

Event::listen('auth.logout', function($user)
{
    // Will log the user out like it normally would
    // Take the time stamp from the login in time
    // Then subtract it from the current time stamp
    // Then with the difference add that to the total time logged in for the user
});

My only issue now is does the auth.logout event get fired when a user clicks on the close button for the browser? I guess a way to test for this would be to listen for the auth.logout event, and if it fires then have an email sent to me (just for testing purposes) to make sure that even closing the browser will end the session + fire the event.

Last updated 1 year ago.
0

arcollector said:

you can track him using js, for example when the user leave the page or close the browser, with js you can trigger an ajax call

to do this you must listen to onunload, with jquey its implemention is super trivial

$( window ).on( 'unload', function() {
   $.ajax( '/user/is-leaving' );
} );

note that you not need to listen a sucess ajax event, just send the request to the server

I'm going to take a look at if this is a cross browser solution. If it is then you just saved me a lot of time!

Last updated 1 year ago.
0

The answer to the second question is no. Auth has no knowledge if a user closes the window.

I would go with the ajax route as well.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.