Hi @brodanoel,
Welcome to the Auth0 Community!
You can redirect the users when using the NextJS SDK from the middleware using a code snippet described in our nextjs-auth0 /EXAMPLES.md github page such as this:
const session = await auth0.getSession(request);
if (!session) {
// user is not authenticated, redirect to login page
return NextResponse.redirect(
new URL("/auth/login", request.nextUrl.origin)
);
}
It is not recommended to expose the access token on the frontend, but another method would be decoding it in your backend, and based on the exp
claim you can determine when the access token is close to expire. You can check out this community post or this one, then pass this information to your frontend.
I hope this helps, and if you have further questions please let me know!
Best regards,
Remus