Logout redirect

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Logout redirect

Post by dlee » 2021-11-23 17:27

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

dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Logout redirect

Post by dlee » 2021-11-24 19:49

Anyone?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1194
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Logout redirect

Post by jsetzer » 2021-11-24 20:34

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.
Kind regards,
<js />

dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Logout redirect

Post by dlee » 2021-11-24 21:06

Thank you sir, I would have not thought of all of these.
Thanks for helping jsetzer.

TD

User avatar
a.gneady
Site Admin
Posts: 1185
Joined: 2012-09-27 14:46
Contact:

Re: Logout redirect

Post by a.gneady » 2021-11-25 10:27

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.
:idea: Calendar plugin: Organize your data into beautiful calendars.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Logout redirect

Post by dlee » 2021-11-25 15:33

Awesome, thank you !

TD

dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Logout redirect

Post by dlee » 2021-11-25 22:42

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

dlee
Veteran Member
Posts: 58
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Logout redirect

Post by dlee » 2021-11-26 16:57

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

Post Reply