From 64dd66dc0398eceef5c099a52748823839d0edef Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:18:47 -0700 Subject: [PATCH] bearer-auth: add to middleware:getAccount --- src/server/lib/middleware.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/lib/middleware.ts b/src/server/lib/middleware.ts index a56ba95..2f0ed0c 100644 --- a/src/server/lib/middleware.ts +++ b/src/server/lib/middleware.ts @@ -3,7 +3,11 @@ import express, { type RequestHandler } from "express" import ServeError from "../lib/errors"; export let getAccount: RequestHandler = function(req, res, next) { - res.locals.acc = Accounts.getFromToken(req.cookies.auth) + res.locals.acc = Accounts.getFromToken(req.cookies.auth || ( + req.header("authorization")?.startsWith("Bearer ") + ? req.header("authorization")?.split(" ")[1] + : undefined + )) next() }