You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I unfortunately do not have the time but maybe this can help someone else in the same spot in the future.
exportconstcreateAccountContext=async({ req }: AccountsRequest): Promise<AccountsModuleContext>=>{if(!req){return{ip: '',userAgent: '',infos: {ip: '',userAgent: '',},};}constheaderName= 'Authorization';letauthToken=(req.headers[headerName]||req.headers[headerName.toLowerCase()])asstring;authToken=authToken&&authToken.replace('Bearer ','');letuserId='';if(authToken){
let sessionToken: string;try{constdecodedAccessToken=jwt.verify(authToken,accountsServer.options.tokenSecret)as{data: JwtData};sessionToken=decodedAccessToken.data.token;userId=decodedAccessToken.data.userId;}catch(err){thrownewAccountsJsError('Auth token is not valid',ResumeSessionErrors.TokenVerificationFailed)}if(!accountsServer.options.useStatelessSession){constsession=awaitaccountsMongo.findSessionByToken(sessionToken);if(!session){thrownewAccountsJsError('Session not found',ResumeSessionErrors.SessionNotFound);}if(!session.valid){thrownewAccountsJsError('Invalid Session',ResumeSessionErrors.InvalidSession);}}}constip=getClientIp(req);
let userAgent: string=(req.headers['user-agent']asstring)||'';if(req.headers['x-ucbrowser-ua']){// special case of UC BrowseruserAgent=req.headers['x-ucbrowser-ua']asstring;}return{
authToken,
userAgent,
userId,
ip,infos: {
userAgent,
ip,},};}
I would like to use
@auth
without having to make a trip to the db on each request.My expected behavior:
context.userId
would be populated byjwtData
and the@auth
directive would work whenexcludeAddUserInContext: true
The text was updated successfully, but these errors were encountered: