Switch to authentication using bearer token.

This commit is contained in:
Mike Cao 2022-01-23 00:32:17 -08:00
parent 698d4d2687
commit d8e831db50
8 changed files with 33 additions and 35 deletions

View file

@ -1,12 +1,15 @@
import { parse } from 'cookie';
import { parseSecureToken, parseToken } from './crypto';
import { AUTH_COOKIE_NAME, TOKEN_HEADER } from './constants';
import { TOKEN_HEADER } from './constants';
import { getWebsiteById } from './queries';
export async function getAuthToken(req) {
const token = parse(req.headers.cookie || '')[AUTH_COOKIE_NAME];
try {
const token = req.headers.authorization;
return parseSecureToken(token);
return parseSecureToken(token.split(' ')[1]);
} catch {
return null;
}
}
export async function isValidToken(token, validation) {