in projects/event-lambdas/src/lib/authentication.ts [63:87]
export async function authenticatePandaUser(
panda: Pick<PanDomainAuthentication,'verify'>,
req: Request,
res: Response,
handler: (user: User) => Promise<void>
): Promise<void> {
const cookie = getPandaCookie(req);
if (!cookie) {
const message =
"No pan-domain authentication cookie present in the request";
applyErrorResponse(res, 403, message);
return;
}
return panda.verify(cookie).then(({status, user}) => {
if(status === AuthenticationStatus.AUTHORISED && user !== undefined) {
return handler(user);
}
else {
applyErrorResponse(res, 403, "Invalid credentials");
return;
}
});
}