You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling auth.getUser on every sessionCheck may introduce latency; consider caching or embedding emailVerified in the session token.
// Get user data to check email verification statusconstuser=awaitauth.getUser(decodedSessionCookie.sub);res.status(200).json({status: 200,message: "Session is valid",data: {user: {email: decodedSessionCookie.email,displayName: decodedSessionCookie.name,emailVerified: user.emailVerified,
Ensure errors from auth.getUser and sendMail are handled separately to avoid exposing internal errors and to provide more granular responses.
// Get user data to check email verification statusconstuser=awaitauth.getUser(decodedSessionCookie.sub);res.status(200).json({status: 200,message: "Session is valid",data: {user: {email: decodedSessionCookie.email,displayName: decodedSessionCookie.name,emailVerified: user.emailVerified,
Wrap the sendMail call in a try-catch block to log failures and prevent unhandled promise rejections. This ensures the function handles SMTP errors gracefully without crashing the process.
Why: Wrapping transporter.sendMail in a try-catch improves resilience by preventing unhandled promise rejections and logging SMTP failures.
Medium
Handle errors in getUser call
Wrap the getUser call in a try-catch to handle potential errors fetching the user and respond with a proper status. This prevents unhandled errors from crashing the session check.
-const user = await auth.getUser(decodedSessionCookie.sub);+let user;+try {+ user = await auth.getUser(decodedSessionCookie.sub);+} catch (error) {+ functions.logger.error("Failed to fetch user for session check", error);+ res.status(500).json({ status: 500, error: "Internal server error" });+ return;+}
Suggestion importance[1-10]: 7
__
Why: Catching errors from auth.getUser in sessionCheck prevents uncaught exceptions and returns a proper 500 response on failure.
Medium
General
Include redirect settings in verification link
Pass ActionCodeSettings with a frontend URL so the verification link redirects correctly after click. This ensures users land on the intended page post-verification.
Why: Adding ActionCodeSettings ensures the verification link redirects users to the correct frontend URL, enhancing UX without impacting core functionality.
Low
Add redirect settings to reset link
Reintroduce ActionCodeSettings when generating the reset link so it points to your frontend reset page. Users will then be routed correctly after clicking the email link.
Why: Reintroducing ActionCodeSettings for generatePasswordResetLink directs users to the frontend reset page, improving navigation but not affecting core logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Implement email verification with nodemailer templates
Send password reset emails via Mailtrap SMTP
Include emailVerified in sessionCheck response
Add verify-account controller and route
Changes walkthrough 📝
auth_controller.ts
Add email verification and reset email featuresfunctions/src/controllers/auth_controller.ts
auth.ts
Add verify-account API routefunctions/src/routes/auth.ts
verifyAccountroute/verify-accountendpointauth_middleware.ts
Update auth middleware exempt routesfunctions/src/middlewares/auth_middleware.ts
/auth/request-resetfrom exempt routescsrf_middleware.ts
Adjust CSRF middleware exempt routesfunctions/src/middlewares/csrf_middleware.ts
/auth/request-resetfrom CSRF exempt routes/auth/verify-accountto exempt list