Page 1 of 1

Logout redirect

Posted: 2021-11-23 17:27
by dlee
I just completed a project using the Appgini generated web app as the backend to a dynamic website. The web app sits in a root subfolder. What I need is when the user logs out of the web app they are redirected to a page on the root. Anyone done this before?

TD

Re: Logout redirect

Posted: 2021-11-24 19:49
by dlee
Anyone?

Re: Logout redirect

Posted: 2021-11-24 20:34
by jsetzer
There are different logout situations next to user, manually clicking on the logout button:

- automatic logout due to session expired timeout
- users having multiple tabs open (or even multiple browser windows open) and then using logout link in one tab
- automatic session reset due to webserver restart or server reboot
- there will be more situations

For a bulletproof solution I think just intercepting a click on the logout button using javascript would only solve one scenario but not the other scenarios.

So there must be additional session state observing on client side, then automatic redirection.

I think, but I may be wrong, there is no hook for those events. So you will have to care for observing the session state on your own.

So, answering your question: I never did this before, as I did not have such a request in the past. You should monitor network requests in dev tools. There is a repeating ajax call from client to server asking for current user. This may be a good place for intercepting login-status.

Re: Logout redirect

Posted: 2021-11-24 21:06
by dlee
Thank you sir, I would have not thought of all of these.
Thanks for helping jsetzer.

TD

Re: Logout redirect

Posted: 2021-11-25 10:27
by a.gneady
One possible way to redirect users when they deliberately click the Sign Out button, as of AppGini 5.97, is to put code similar to this in hooks/__bootstrap.php (this hook file is executed before sending any output to users so it can safely send a redirection header and exit):

Code: Select all

<?php
	if(!empty($_GET['signOut'])) {
		header('Location: https://google.com/'); // replace with destination URL
		die();
	}
?>
Of course, the above code doesn't address the other scenarios mentioned by Jan. In the case of session expiry, the typical behavior is that the login page would be displayed, but trying to intercept this might interfere with users trying to log in.

Re: Logout redirect

Posted: 2021-11-25 15:33
by dlee
Awesome, thank you !

TD

Re: Logout redirect

Posted: 2021-11-25 22:42
by dlee
As it turns out Appgini v5.97 does not create the file /hooks/bootstrap.php. In all fairness, the project was originally created with v5.98 but I have reverted back to v5.97 to get recaptcha to work. I manually created this file and added the code that a.gneady posted above but redirect did not work. Any ideas why this is?

Thanks for helping,
TD

Re: Logout redirect

Posted: 2021-11-26 16:57
by dlee
OK, I had tried this before but this time I got the syntax correct, works perfectly. I added this code to /hooks/footer-extras.php:

Code: Select all

<script>
	$j("a:contains('Sign Out')").attr("href","http://google.com");
</script
TD