NextAuth: How to protect route groups without middleware?

Because I'm not using SSR, I don't have access to middlewares. My first idea was moving useSession({required: true}) up, from my pages to my layout. But that's not working out because useSession() only works within <SessionProvider> {children} </SessionProvider>. Does that mean I need to create another wrapper between <SessionProvider> and my pages? Like:
<SessionProvider>
<AuthChecker> // runs useSession({required: true})
{children}
</AuthChecker>
</SessionProvider>
<SessionProvider>
<AuthChecker> // runs useSession({required: true})
{children}
</AuthChecker>
</SessionProvider>
And run useSession({required: true}) inside AuthChecker ? Or is there a better way?
3 Replies
arete
arete17mo ago
Client API | NextAuth.js
The NextAuth.js client library makes it easy to interact with sessions from React applications.
arete
arete17mo ago
you can create something like this
Amir
AmirOP17mo ago
Thanks Fatwa, will look into it.
Want results from more Discord servers?
Add your server