@@ -292,6 +292,7 @@ export class DbAuthHandler<
292
292
corsContext : CorsContext | undefined
293
293
sessionExpiresDate : string
294
294
webAuthnExpiresDate : string
295
+ encryptedSession : string | null = null
295
296
296
297
// class constant: list of auth methods that are supported
297
298
static get METHODS ( ) : AuthMethodNames [ ] {
@@ -402,9 +403,9 @@ export class DbAuthHandler<
402
403
}
403
404
404
405
try {
405
- const [ session , csrfToken ] = decryptSession (
406
- getSession ( this . cookie , this . options . cookie ?. name )
407
- )
406
+ this . encryptedSession = getSession ( this . cookie , this . options . cookie ?. name )
407
+
408
+ const [ session , csrfToken ] = decryptSession ( this . encryptedSession )
408
409
this . session = session
409
410
this . sessionCsrfToken = csrfToken
410
411
} catch ( e ) {
@@ -568,12 +569,8 @@ export class DbAuthHandler<
568
569
569
570
async getToken ( ) {
570
571
try {
571
- const user = await this . _getCurrentUser ( )
572
-
573
- // need to return *something* for our existing Authorization header stuff
574
- // to work, so return the user's ID in case we can use it for something
575
- // in the future
576
- return [ user [ this . options . authFields . id ] ]
572
+ // Just return the encrypted session cookie, to be passed back in the Authorization header
573
+ return [ this . encryptedSession || '' ]
577
574
} catch ( e : any ) {
578
575
if ( e instanceof DbAuthError . NotLoggedInError ) {
579
576
return this . _logoutResponse ( )
@@ -1435,6 +1432,7 @@ export class DbAuthHandler<
1435
1432
_ok ( body : string , headers = { } , options = { statusCode : 200 } ) {
1436
1433
return {
1437
1434
statusCode : options . statusCode ,
1435
+ // @TODO should we do a null check in body?!
1438
1436
body : typeof body === 'string' ? body : JSON . stringify ( body ) ,
1439
1437
headers : { 'Content-Type' : 'application/json' , ...headers } ,
1440
1438
}
0 commit comments