How to create a single public route with Auth0 authentication

Hi
We have a single page React app that uses auth0-spa.js and authenticates the users flawlessly. We need to create a public route within our react app(wrapped in Auth0Provider) that does not require authentication. for example if you visit example.com/public you will be able to see the content of that page but for any other route you will be taken to the login page (as its happening right now)
Any ideas how I can achieve this public route?
I appreciate any help.

Hi @fmozaffari,

Have you seen our react quickstart? It demonstrates a react app with a home page and a private route. The home page at / is accessible whether or not the user is authenticated. The profile page at /profile is protected.

Let me know if this makes sense,
Dan

1 Like

Thank you Dan.
I will take a look at that and see if it works with my set up.

1 Like

After looking at your suggestion creating private routes based on that example makes sense. One other piece of the puzzle is that currently if you type in a route in my app and you are not authenticated you are taken to the login page. I need to keep that functionality in my app but make an exception so that if you visit my /public route and you are not authenticated you won’t be take to the login page.

Could you post an example of the code? It sounds like you are following a different pattern than our quickstart.

Right. I was not following the method in which you define a PrivateRoute. I am refactoring this to look like the quickstart pattern. thank you for your help

2 Likes

No problem. Let us know if there is anything else we can do!

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.