forked from FoundKeyGang/FoundKey
Reassure typechecker about token in authenticate
This commit is contained in:
parent
fb80fd1fbd
commit
eff9dbb5ee
1 changed files with 4 additions and 3 deletions
|
@ -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]> => {
|
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
|
// check if there is an authorization header set
|
||||||
if (authorization != null) {
|
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
|
// check if OAuth 2.0 Bearer tokens are being used
|
||||||
// Authorization schemes are case insensitive
|
// Authorization schemes are case insensitive
|
||||||
if (authorization.substring(0, 7).toLowerCase() === 'bearer ') {
|
if (authorization.substring(0, 7).toLowerCase() === 'bearer ') {
|
||||||
token = authorization.substring(7);
|
maybeToken = authorization.substring(7);
|
||||||
} else {
|
} else {
|
||||||
throw new AuthenticationError('unsupported authentication scheme');
|
throw new AuthenticationError('unsupported authentication scheme');
|
||||||
}
|
}
|
||||||
} else if (bodyToken != null) {
|
} else if (bodyToken != null) {
|
||||||
token = bodyToken;
|
maybeToken = bodyToken;
|
||||||
} else {
|
} else {
|
||||||
return [null, null];
|
return [null, null];
|
||||||
}
|
}
|
||||||
|
const token: string = maybeToken;
|
||||||
|
|
||||||
if (isNativeToken(token)) {
|
if (isNativeToken(token)) {
|
||||||
const user = await localUserByNativeTokenCache.fetch(token,
|
const user = await localUserByNativeTokenCache.fetch(token,
|
||||||
|
|
Loading…
Reference in a new issue