othiagocruz
03/23/2021, 2:29 PMothiagocruz
03/23/2021, 2:31 PMrp
03/23/2021, 2:45 PMothiagocruz
03/23/2021, 2:46 PMothiagocruz
03/23/2021, 2:46 PMrp
03/23/2021, 2:46 PMrp
03/23/2021, 2:46 PMothiagocruz
03/23/2021, 2:47 PMrp
03/23/2021, 2:48 PMrp
03/23/2021, 2:48 PMothiagocruz
03/23/2021, 2:48 PMothiagocruz
03/23/2021, 2:48 PMothiagocruz
03/23/2021, 2:48 PMrp
03/23/2021, 2:57 PMverifySession
, you can use getSession
like so:
import supertokens from "supertokens-node";
import {getSession} from "supertokens-node/recipe/sessions";
let session;
try {
session = await getSession(req, res);
} catch (err) {
if (supertokens.Error.isErrorFromSuperTokens(err) && err.type !== "GENERAL_ERROR") {
if (err.type === "TRY_REFRESH_TOKEN") {
supertokens.errorHandler()(err, req, res, () => {})
} else {
// unauthorised error. We let the API run to allow anonymous users
}
} else {
throw err;
}
}
if (session === undefined) {
// user is anonymous
} else {
// user is logged in
}
othiagocruz
03/23/2021, 2:59 PMrp
03/23/2021, 3:00 PMrp
03/23/2021, 3:01 PMgetSession
throws general error, you handle it like any other error in your APIs. If it throws a try refresh token error, you let us handle it (hence the supertokens.errorHandler()(err, req, res, () => {})
). If it throws an unauthorised error, you can continue the API logic with an anonymous user.
We will probably add some flag to verySession that allows the API to be called even if the user is not logged in, in which case this will become much easier .othiagocruz
03/23/2021, 3:03 PMrp
03/23/2021, 3:03 PMothiagocruz
03/23/2021, 3:04 PMJoeBlow
03/24/2021, 11:31 PMJoeBlow
03/24/2021, 11:33 PMrp
03/25/2021, 4:59 AMrp
03/25/2021, 5:02 AMothiagocruz
03/31/2021, 12:39 PMothiagocruz
03/31/2021, 12:39 PMinfo - Checking validity of types
info - Using external babel configuration from C:\offscript\storefront\.babelrc
info - Creating an optimized production build
Failed to compile.
ModuleNotFoundError: Module not found: Error: Can't resolve 'react-router-dom' in 'C:\offscript\storefront\node_modules\supertokens-auth-react\lib\build'
> Build error occurred
Error: > Build failed because of webpack errors
at C:\offscript\storefront\node_modules\next\dist\build\index.js:17:924
at async Span.traceAsyncFn (C:\offscript\storefront\node_modules\next\dist\telemetry\trace\trace.js:5:584)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
othiagocruz
03/31/2021, 12:40 PMothiagocruz
03/31/2021, 12:40 PMrp
03/31/2021, 12:46 PMrp
03/31/2021, 12:46 PM