rp
02/28/2022, 10:11 AMrp
02/28/2022, 10:11 AMrp
02/28/2022, 10:11 AMpages/app/auth/[[...path]].js
Bruno Diferente
02/28/2022, 10:12 AMrp
02/28/2022, 10:13 AMrp
02/28/2022, 10:13 AMmantis
03/01/2022, 4:50 AMprachi
03/01/2022, 11:31 AMrajivharlalka
03/01/2022, 2:23 PMmessage: unauthorised
also what is the path of the function in the sdk.Tried to find but couldnt exactly locate it.rajivharlalka
03/01/2022, 5:12 PMrp
03/01/2022, 5:12 PMrajivharlalka
03/01/2022, 5:14 PMrajivharlalka
03/01/2022, 5:14 PMrajivharlalka
03/01/2022, 5:15 PMrp
03/01/2022, 5:16 PMrajivharlalka
03/01/2022, 5:18 PMrp
03/01/2022, 5:18 PMrajivharlalka
03/01/2022, 5:20 PMrp
03/01/2022, 5:39 PMts
function myCustomMiddleware(verifySessionOptions?: Session.VerifySessionOptions) {
return async (req: express.Request, res: express.Response, next: express.NextFunction) => {
try {
let session = await Session.getSession(req, verifySessionOptions);
if (session === undefined) {
if (verifySessionOptions?.sessionRequired === false) {
return next();
} else {
throw Error("Should never come here");
}
}
let userId = session.getUserId();
// TODO: fetch info from mongo and attach to req.user = ....
next();
} catch (err) {
next(err);
}
}
}
app.get("/some-api", myCustomMiddleware(), (req, res) => {
// TODO:...
})
note that the above requires that you have added the supertokens errorHandler to the your express app (should be done if you follow the backend quick setup correctly).rp
03/01/2022, 5:40 PMgetSession
function here: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/session-verification-in-api/get-sessionrajivharlalka
03/01/2022, 5:41 PMrp
03/01/2022, 5:41 PMrp
03/01/2022, 5:41 PMrajivharlalka
03/01/2022, 5:42 PMrajivharlalka
03/01/2022, 6:12 PMrp
03/01/2022, 6:12 PMrajivharlalka
03/01/2022, 6:12 PMrajivharlalka
03/01/2022, 6:12 PMvikas2cool21
03/01/2022, 6:13 PMrp
03/01/2022, 6:13 PM