Reassure typechecker about token in authenticate

This commit is contained in:
Michcio 2022-09-25 17:21:30 +02:00 committed by Johann150
parent fb80fd1fbd
commit eff9dbb5ee
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -16,7 +16,7 @@ export class AuthenticationError extends Error {
}
export default async (authorization: string | null | undefined, bodyToken: string | null | undefined): Promise<[CacheableLocalUser | null | undefined, AccessToken | null | undefined]> => {
let token: string | null = null;
let maybeToken: string | null = null;
// check if there is an authorization header set
if (authorization != null) {
@ -27,15 +27,16 @@ export default async (authorization: string | null | undefined, bodyToken: strin
// check if OAuth 2.0 Bearer tokens are being used
// Authorization schemes are case insensitive
if (authorization.substring(0, 7).toLowerCase() === 'bearer ') {
token = authorization.substring(7);
maybeToken = authorization.substring(7);
} else {
throw new AuthenticationError('unsupported authentication scheme');
}
} else if (bodyToken != null) {
token = bodyToken;
maybeToken = bodyToken;
} else {
return [null, null];
}
const token: string = maybeToken;
if (isNativeToken(token)) {
const user = await localUserByNativeTokenCache.fetch(token,