NextJS Session Recipe Documentation
# support-questions-legacy
a
NextJS Session Recipe Documentation
Hi @rp_st @Adiboi, on the Supertokens website, specifically for the Sessions Recipe, I can't find useful code examples for the server side code on NextJS. Is there a repo or gist that can help me with that?
r
Uhmm. So that’s a missing part in the docs. What you can do is follow the guide for emailpassword recipe in NextJS but ignore all the emailpassword. Recipe specific things.
And to create a new session, you can see the docs for that part in session recipe. That has NextJS snippets.
a
@rp_st thanks a lot, I may have more questions as I implement
r
Sounds good.
a
Hi @rp_st so in my login api endpoint I have this:
Copy code
await superTokensNextWrapper(
      async (next) => {
        await createNewSession(req, user?.userId, {
          userId: user?.userId ?? "",
          firstname: user?.firstname ?? "",
          lastname: user?.lastname ?? "",
          email: user?.email ?? "",
          role: user?.role ?? "admin",
        });
      },
      req,
      res
    );
but for some reason I keep getting this error: Error while setting header with key: front-token and value: {{token value here}}
I don't know if this has anything to do with it but, I also disabled refresh tokens here in the recipeList:
Copy code
SessionNode.init({
        override: {
          apis: (originalImplementation) => {
            return {
              ...originalImplementation,
              refreshPOST: undefined,
            };
          },
        },
      }),
when I had it enabled, my login api endpoint call kept getting called in an endless loop
@rp_st & @Adiboi, any help you can lend would be great
thanks
r
Hmmm. That’s odd. Can you reenable the refresh api and also enable the backend and frontend debug logs and show me the output of them during login?
Also, a screenshot of the response headers of the login API
Response and request headers *
a
index.tsx file getServerSideProps
backendConfig.ts file
part of my login.ts file (NextJS API)
login API endpoint header screenshots
@rp_st & @Adiboi
r
The first argument to createNewSession should be res. Not req.
2 Views