Add support for token validation for headers
This commit is contained in:
parent
4a34daa54c
commit
d3ac213590
|
@ -4,6 +4,11 @@ import { getAccessToken } from "../db/accessTokens";
|
|||
export default async function validateAccessToken(request: Request): Promise<Response | AccessToken> {
|
||||
let accessToken = request.url.split("?")[1]?.split("&").filter((x) => x.split("=")[0] === "token")[0].split("=")[1];
|
||||
|
||||
if(accessToken === undefined) {
|
||||
const authorization = request.headers.get("Authorization");
|
||||
if(authorization !== null && authorization.startsWith("Bearer ")) accessToken = authorization.split(" ")[1];
|
||||
}
|
||||
|
||||
const cookies = request.headers.get("Cookie")?.split(";").map((x) => x.trim().split("=")) ?? [];
|
||||
|
||||
if(accessToken === undefined) accessToken = cookies.filter((x) => x[0] === "sessionToken")[0]?.[1];
|
||||
|
|
Loading…
Reference in New Issue