How do I auto direct back to Login if the user isn't logged in?

I’m looking for a way to autodirect the user back to the login if they aren’t logged in that way you can’t type the route in the URL. I tried to do this through a security restrict and it didn’t work the way I intended. Please let me know any possible solutions to this issue.

Security Enforcer is the way to go. Did you add it your your page?

I’m confused on what you mean here exactly? Do I need to create an API. I currently have one that restricts those who aren’t administrators from specific pages and boots them back to the login, but when I tried to copy this for anyone who isn’t logged in it didn’t work. I connected this through server side data server connect.

Use the Dynamic Events of the Server Connect that checks for the user (who am I). Put a browser goto on the unauthorized event.

1 Like

I already have this logic in place. Maybe my whoami doesn’t check if they’re logged in or not. If not how would I go about solving this?


What do you see when you refresh the page in Network tools for that server connect?

What’s your server model?
If php:

Can you show us the security provider enforcer?
(App - > security provider enforcer)
Also show us the security provider under globals.

If: node:

Can you remove the Security Identity and replace it with a Security Restrict?

image

Why can’t you just use the Security Enforcer on your page like I posted? It’s exactly what it is used for.

Select App in your App Connect panel and add the enforcer. Easy Peasy …

The Security Provider Enforcer is only for php projects. There’s a slightly different process for node.js which @franse linked above.

3 Likes

So what I did was make another API called “isloggedin” and this has a security restrict where permissions are blank, and the login URL routes to my Login page. When I add this API to one of my pages though on the desktop it reports an error because the login page routes to the login page therfore it keeps loading. I’m not sure why that is because my login page doens’t have the “isloggedin” api attached to it.

Do I need the database single query that looks for my Users as I do for the “whoami” API? If so why is this a necessary step in the process.

Hey, you probably have a conflict with multiple server connects.

If you added the server connect to the App component as shown in the documentation, then I would check the other server connects and ensure you don’t have any dynamic events with browser go-to actions.

Sounds good, I’ll keep troubleshooting

I’ve resolved this issue. It was as simple as making a security restrict where the login URL routes to my login page. I believe there was a bug because originally, I added it to my layout page as a server action. Even though I removed it I believe it must’ve still been referencing this, so it kept trying to reload the login page till it timed out. I reloaded from a previous version of the project and redid the previous steps, and it works as I originally intended.

Thanks for all the help everyone.