Optional login for whole app

Hi, I’m a new auth0 user. Our app is a SPA in react with react-router v6.

I’m trying to let users either use auth or bypass it completely. I’ve successfully implemented auth0-react-spa by having the whole app wrapped in an Auth0Context, but that requires all users to login. When I try to make it conditional, I can’t keep login state across page refresh. I’m wondering what the pattern is to keep that context.

Here’s my auth0 integration:

I’d like to make auth optional for users. If I wrap the root routes in Auth0Context like in the auth0-react-ap guide, then all users have to go through the auth flow.

What I’ve tried here is if isAuthenticated then use Auth0Context, otherwise, just bare app, here:

This lets users choose to authenticate by clicking the top-right login button, but a page refresh loses auth.