demisel
05/16/2023, 3:16 PMgetServerSideProps
with NextJS, my calls to SessionNode.getSession(req, res)
end up with an error that says
SessionError: Session does not exist. Are you sending the session tokens in the request with the appropriate token transfer method?
I guess something may be wrong with my config.
I am not sure whether `config.supertokens.connectionURI`should be an url that points to a supertokens core, or a supertokens backend, but either gives the same result. When looking at my developper console, I see the cookies being sent to my nextjs app.
Any advice on how to solve this ?rp_st
05/16/2023, 3:18 PMdemisel
05/16/2023, 3:19 PMsFrontToken
& st-last-access-token-update
in all requests between the browser and my nextjs apprp_st
05/16/2023, 3:25 PMdemisel
05/16/2023, 3:29 PMcom.supertokens {t: "2023-05-16T15:27:50.044Z", message: "getSession: Started", file: "/[...]/backend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:54:18" sdkVer: "14.0.0"} +0ms
com.supertokens {t: "2023-05-16T15:27:50.045Z", message: "getSession: Wrapping done", file: "/[...]/backend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:62:18" sdkVer: "14.0.0"} +0ms
com.supertokens {t: "2023-05-16T15:27:50.045Z", message: "getSession: optional validation: false", file: "/[...]/-backend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:72:18" sdkVer: "14.0.0"} +0ms
com.supertokens {t: "2023-05-16T15:27:50.046Z", message: "getSession: UNAUTHORISED because accessToken in request is undefined", file: "/[...]/backend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:120:22" sdkVer: "14.0.0"} +0ms
That last one looks promisingrp_st
05/16/2023, 3:30 PMrp_st
05/16/2023, 3:30 PMdemisel
05/16/2023, 3:31 PMGET /_next/static/development/_devMiddlewareManifest.json HTTP/1.1
Host: localtest.me:7331
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/112.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localtest.me:7331/fr
rid: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2tlbkhhc2gxIjpudWxsLCJhbnRpQ3NyZlRva2VuIjpudWxsLCJpc3MiOiJodHRwOi8vYXBpLmxvY2FsdGVzdC5tZToxMzM3L2F1dGgiLCJzdC1ldiI6eyJ2Ijp0cnVlLCJ0IjoxNjg0MjQ5NTg5NjMwfX0.pK4IAS1cyPVf9tJ5xXbDYOUIZcVYDfxAIdTDVLgb5YRlrMcL1lN_s2v5yAUkPwxlF4ysBYesVynXeYc2hjbIMICDXWP4HeOQezDieer4LaeAIM-Nq57o3StmsrBVdaVlsa_QClfUlRSZ8vtFaETMKQblXUKSA0lANu1QGlfHjrBgxddYGbwYra1_fCST9KQ9GH2oFd6Ma0w-NYcEywpN-waPt_lX6qy4kpr7_2JBxJrsB60XS4Y53QfmxBfBzOKB8hgkXCiOPtWiutkX_0uucRc7ja4nrfMp4q0eLEgi93BC-jP46GqTlr6lB6WhyYesKTg0CIV1hvq10mCHljS-Yg
Pragma: no-cache
Cache-Control: no-cache
rp_st
05/16/2023, 3:33 PMsAccessToken
rp_st
05/16/2023, 3:34 PMdemisel
05/16/2023, 3:35 PM"supertokens-node": "^14.0.0",
,
In the frontend :
"supertokens-auth-react": "^0.31.3",
"supertokens-node": "^13.1.5",
"supertokens-web-js": "^0.5.0",
rp_st
05/16/2023, 3:35 PMdemisel
05/16/2023, 3:36 PM"next": "^13.2.4",
rp_st
05/16/2023, 3:36 PMdemisel
05/16/2023, 3:37 PMSessionNode.getSession
rp_st
05/16/2023, 3:37 PMrp_st
05/16/2023, 3:37 PMdemisel
05/16/2023, 3:39 PMlocaltest.me:7331
, on which I'm trying to get ssr to work
And I have a backend at localtest.me:1337
, that I use to login and fetch datarp_st
05/16/2023, 3:39 PMdemisel
05/16/2023, 3:39 PMrp_st
05/16/2023, 3:40 PMdemisel
05/16/2023, 3:40 PMrp_st
05/16/2023, 3:41 PMrp_st
05/16/2023, 3:41 PMdemisel
05/16/2023, 3:44 PMrp_st
05/16/2023, 3:44 PMdemisel
05/16/2023, 3:48 PMSessionError: Failed to verify access token
at Object.<anonymous> (/[...]/frontend/node_modules/supertokens-node/lib/build/recipe/session/accessToken.js:214:19)
at Generator.throw (<anonymous>)
at rejected (/[...]/frontend/node_modules/supertokens-node/lib/build/recipe/session/accessToken.js:72:44)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'TRY_REFRESH_TOKEN',
payload: undefined,
errMagic: 'ndskajfasndlfkj435234krjdsa',
fromRecipe: 'session'
}
I guess that's ok and it's up to me to manage this case nowrp_st
05/16/2023, 3:49 PMrp_st
05/16/2023, 3:49 PMdemisel
05/16/2023, 3:49 PMdemisel
05/16/2023, 4:16 PMneeds-refresh
as pageProp if needed, but end up with an infinite loop of attempts to refresh.
Using this in my _app.tsx :
typescript
useEffect(() => {
async function doRefresh() {
if (pageProps.fromSupertokens === "needs-refresh") {
if (await Session.attemptRefreshingSession()) {
location.reload();
} else {
null;
}
}
}
doRefresh();
}, [pageProps.fromSupertokens]);
if (pageProps.fromSupertokens === "needs-refresh") {
return null;
}
It seems like await SessionNode.getSession(req, res);
keeps answering TRY_REFRESH_TOKEN.
I had set a short lifetime for sessions in my supertokens core docker-compose, but have removed it since. Am I missing something ?rp_st
05/16/2023, 4:17 PMdemisel
05/16/2023, 4:19 PMrp_st
05/16/2023, 4:19 PMrp_st
05/16/2023, 4:20 PMrp_st
05/16/2023, 4:20 PMdemisel
05/16/2023, 4:20 PMdemisel
05/16/2023, 4:24 PM2023-05-16T16:22:18.177Z com.supertokens {t: "2023-05-16T16:22:18.176Z", message: "getSession: Started", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:54:18" sdkVer: "14.0.2"}
2023-05-16T16:22:18.177Z com.supertokens {t: "2023-05-16T16:22:18.177Z", message: "getSession: Wrapping done", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:62:18" sdkVer: "14.0.2"}
2023-05-16T16:22:18.178Z com.supertokens {t: "2023-05-16T16:22:18.178Z", message: "getSession: optional validation: false", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:72:18" sdkVer: "14.0.2"}
2023-05-16T16:22:18.179Z com.supertokens {t: "2023-05-16T16:22:18.179Z", message: "getSession: got access token from cookie", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:81:30" sdkVer: "14.0.2"}
2023-05-16T16:22:18.181Z com.supertokens {t: "2023-05-16T16:22:18.180Z", message: "getSession: using cookie transfer method", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:108:22" sdkVer: "14.0.2"}
2023-05-16T16:22:18.182Z com.supertokens {t: "2023-05-16T16:22:18.181Z", message: "getSession: Value of doAntiCsrfCheck is: false", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/sessionRequestFunctions.js:136:18" sdkVer: "14.0.2"}
2023-05-16T16:22:18.183Z com.supertokens {t: "2023-05-16T16:22:18.182Z", message: "getSession: Started", file: "/frontend/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:170:26" sdkVer: "14.0.2"}
SessionError: Failed to verify access token
at Object.<anonymous> (/frontend/node_modules/supertokens-node/lib/build/recipe/session/accessToken.js:214:19)
...{
type: 'TRY_REFRESH_TOKEN',
payload: undefined,
errMagic: 'ndskajfasndlfkj435234krjdsa',
fromRecipe: 'session'
}
rp_st
05/16/2023, 4:24 PMrp_st
05/16/2023, 4:25 PMdemisel
05/16/2023, 4:25 PMdemisel
05/16/2023, 4:26 PMrp_st
05/16/2023, 4:26 PM/frontend/node_modules/supertokens-node/lib/build/recipe/session/accessToken.js:214
file and then add a print statement for printing out the err
? (here: https://github.com/supertokens/supertokens-node/blob/master/lib/build/recipe/session/accessToken.js#L214)demisel
05/16/2023, 4:26 PMrp_st
05/16/2023, 4:26 PMrp_st
05/16/2023, 4:26 PMdemisel
05/16/2023, 4:27 PMrp_st
05/16/2023, 4:27 PMrp_st
05/16/2023, 4:27 PMdemisel
05/16/2023, 4:30 PMrp_st
05/16/2023, 4:31 PM