Hey,
I’m looking to create a site that is entirely restricted to users who are logged in. I have found the role based redirects, but can’t seem to get it working how it needs to. I need the redirects to:
- Redirect any unauthenticated user from any route, to /login/ route.
- Redirect any authenticated user from /login/ to /
Is this possible? I’ve got as far as:
# Always allow access to the login page
/login/ /login/ 200
# If visitor has 'user' with role of editor set, let them in.
/* 200! Role=user
# else redirect back to login
/* /login/ 401!
Many thanks!
I think this should do it:
/* /index.html 200! Role=user
/* /login/ 302!
Taken from: Restrict access to your sites with role based redirects
Thanks! This does seem to redirect unauthenticated, but not redirect logged in users back to the homepage
That’s strange. It’s an official guide from Netlify. Have you set the roles correctly?
I am! The non-authenticated redirect works well
Well, I think a Support Engineer can get this checked for you. I’ve upgraded the thread.
1 Like
Thanks! Generally all I’m trying to do it gate an entire site, so a user requires a login to access the site. Once signed in, it returns to the homepage so the user can access.
I can’t find a demo or blog post on anything that does that specifically, which seems the simplest implementation of a gated site
It does, but I’d prefer to do this server side, rather than client side
Hey there, @ryangittings
I just wanted to check in and see if you were still having questions about this topic. Let us know if you have found a solution, if you used what Hrishikesh suggested, or if you are looking for guidance still.
Thanks