On NextJS I:
Created the frontend config file
Using ThirdPartyEmailPasswordReact.init(...)
Using Session.init({sessionTokenBackendDomain: ".domain.com"}),
Created the backend config file
Using ThirdPartyEmailPasswordNode.init(...)
Using Dashboard.init()
Using SessionNode.init({cookieDomain: ".domain.com"}),
Created supertokensProvider and wrapped my layout with it to initialize the frontend config
Created app/auth/[[...path]]/page.tsx
Created app/api/auth/[[...path]]/route.ts
Modified my fetch function to have
Fetches to backend api at
https://back.domain.com/api/
On Express I:
Setup SuperTokens.init
Using ThirdPartyEmailPasswordNode.init(...)
Using Session.init({cookieDomain: ".domain.com"})
Setup CORS
cors({
origin: ['https://front.domain.com', 'https://back.domain.com'],
allowedHeaders: ["content-type", ...SuperTokens.getAllCORSHeaders()],
methods: ["GET", "PUT", "POST", "DELETE"],
credentials: true,
})
Added verifySession() to my api routes
Order of initialization:
Express
SuperTokens.init
CORS
Supertokens-Express middleware
Express router
Supertokens error handler
Express error handler
I am able to go to the /auth page and sign in or sign up as the user.
If I run fetch from my "use client" page to an Express api route which has verifySession() then I am able to successfully access routes which use verifySession().
If I run a fetch from my server component page to an Express api route which has verifySession() then my NextJS console shows "Error getting response: { message: 'unauthorised' }".
If I run a fetch from my server component page to an Express api route without verifySession() then I am able to successfully access the unprotected route.
So it looks like I am only able to verify the user session when using client sided components.