anybody done supertokens integration with nextjs +...
# general
c
anybody done supertokens integration with nextjs + graphql. I want to use nextjs app router, and use layouts to manage protected pagess based on the role of the user. Not sure how to do this with supertokens-auth-react
r
Hey @chath_s_85723
You can follow the NextJS guide we have for the frontend parts only and for ssr. So ignore the use of supertokens-node to add the middleware.
c
Hi
r
For the backend, you can follow our backend quick setup + graphql guide
c
sorry.. which ones?
r
Everything except the 3, 4, 6
As in ignore 3, 4, 6
c
ok..
but i cant figure out how i can use the session from the frontend SDK to create protected routes
If for instance i want to use the layout to monitor the session, and redirect unauthenticated users to the auth route?
Would I instead need to wrap the client components in individually as in no.5 about?
or is there a better way to do it where i can check the session and route users in the layout instead?
r
You can check in the layout itself too. But that your layout would have to be a client component
It’s sort of all in our guide. If you have a very specific question, I’m happy to help
c
i see..
"but that your layout would have to be a client component" <-- couldnt find this part in the guide
may have missed it
r
If you see the SessionAuth guide, it should tell u that it’s only if the layout is a client component.
c
yes correct..
but layout cannot be a client component, if i understand correct
only page can be a client component
r
I’m not sure. Maybe
We have docs for server side session checking as well.
That should be number 7.
Sorry, number 5, second part.
c
yea which uses the sessionUtils which needs the backend configs
where my nextjs doesnt have backendconfigs, cos the app using graphql
sorry its bits and pieces from everywhere that i need to take i think. Cant really follow the guide step-by-step because my architecture is different. So a bit confused 🙂
r
So you can add the backend config in NextJS as well just keeping the session recipe
c
in that case what would the "connectionURI" be?
r
Same as what’s in the other backend
c
hmm the supertokens core? but its not really exposed, cos its two different servers for my case
r
Not sure then..
I’m sure u can figure it out 🙂
c
ok thanks for thinking along
o
You can create your own wrapper in a separate file, make that wrapper a client component and have the SessionAuth wrapper inside yours. I’ll send you a screenshot of what I mean later.
2 Views