From 81e10a390bfdc2555958d1c514dc70f2138f583b Mon Sep 17 00:00:00 2001 From: Lucemans Date: Sat, 1 Jan 2022 12:32:24 +0100 Subject: [PATCH] Support Bearer Tokens --- src/auth/useAuth.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/auth/useAuth.ts b/src/auth/useAuth.ts index bcef4005..aa6bd337 100644 --- a/src/auth/useAuth.ts +++ b/src/auth/useAuth.ts @@ -14,7 +14,11 @@ export type AuthRequest = Request & { export const useAuth: RequestHandler = NextHandler( async (request: AuthRequest, response) => { if (!request.headers.authorization) return NoPermission(); - const auth = request.headers.authorization; + let auth = request.headers.authorization; + + if (auth.toLowerCase().startsWith('Bearer ')) { + auth = auth.slice(0, Math.max(0, 'Bearer '.length)); + } const decoded = decode(auth) as { account: string; value: number };