Fix crash on invalid data.

This commit is contained in:
Mike Cao 2020-08-23 19:21:39 -07:00
parent ebad20ce0e
commit 1aa9689b4f

View File

@ -18,9 +18,13 @@ export function use(middleware) {
export const useCors = use(cors());
export const useSession = use(async (req, res, next) => {
const session = await verifySession(req).catch(e => {
let session;
try {
session = await verifySession(req);
} catch (e) {
return serverError(res, e.message);
});
}
if (!session) {
return badRequest(res);
@ -31,9 +35,13 @@ export const useSession = use(async (req, res, next) => {
});
export const useAuth = use(async (req, res, next) => {
const token = await verifyAuthToken(req).catch(e => {
let token;
try {
token = await verifyAuthToken(req);
} catch (e) {
return serverError(res, e.message);
});
}
if (!token) {
return unauthorized(res);