My stack: Next.js frontend Nest.js backend Postgr...
# support-questions-legacy
j
My stack: Next.js frontend Nest.js backend Postgres 1. Getting Next.js to work with SuperTokens seems easy. However, once the user has logged into the Next.js app and starts making API calls, how does the Nest.js app know if the user has logged in from the API calls? 2. I'd like to store user details such as email, auth provider, etc. on my own Postgres database. Is there some kind of callback that will send a request to my API when the user changes email or a new account has just been created?
r
Hey!
So first of, you want to only integrate the frontend SDK in NextJS. So in the guide we have for NextJS, ignore all the parts to do with supertokens-node SDK.
And also follow the nestjs guide which will setup the supertokens-node SDK for nestjs
So that will enable you to have a session between NextJS frontend and nestjs backend. And then nestjs can use the auth guard (which uses our session verification function) to know if a user is logged in or not
About the second part, checkout the post login operations section. It allows you to override the sign up API to do anything you like after the user has signed up
For things like change in email, you can override the recipe function for that and once the original implementation is done, you can update your db
@joel04425
Also, with supertokens, you don’t need to add any web hooks in your api. It’s all integrated within your own api layer. So all customisations happen Via the backend SDK
j
How do I validate requests if I want to add microservices?
r
Couple of ways: - You can get the sessionHandle from the request and pass that to your microservice. The microservice can query the core to check if the session handle is valid and get the user info from there. - You can use the JWT recipe we have to create a JWT with whatever contents you want and then pass that JWT to the microservice. The microservice can validate that JWT to validate the request.
j
Does the Next.js front-end app have to call a supertokens API to validate the session on every page request?
r
Not unless you want to do session verification in server side render.
27 Views