Skip to content

Commit

Permalink
Fixed Auth Middleware with verifySessionCookie
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jun 21, 2024
1 parent 71c1444 commit b2387c2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ declare global {
}

export async function authMiddleware(req: Request, res: Response, next: NextFunction) {
const { token } = req.cookies;
if (!token) {
const sessionCookie = req.cookies.session || '';
console.log('sessionCookie:', sessionCookie);
if (!sessionCookie) {
return next();
}
try {
const idToken = await admin.auth().verifyIdToken(token);
const idToken = await admin.auth().verifySessionCookie(sessionCookie, true);
console.log('idToken:', idToken);
const { uid, displayName, email } = await admin.auth().getUser(idToken.uid);
req.user = { id: uid, email: email!, name: displayName! };
next();
Expand Down

0 comments on commit b2387c2

Please sign in to comment.