Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the email verification #1480

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/web/app/api/auth/reset-password/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export async function POST(req: NextRequest) {

const { identifier } = tokenFound;

const user = await prisma.user.findUniqueOrThrow({
where: {
email: identifier,
},
select: {
emailVerified: true,
},
});

await prisma.$transaction([
// Delete the token
prisma.passwordResetToken.deleteMany({
Expand All @@ -56,6 +65,7 @@ export async function POST(req: NextRequest) {
data: {
passwordHash: await hashPassword(password),
lockedAt: null, // Unlock the account after a successful password reset
...(!user.emailVerified && { emailVerified: new Date() }), // Mark the email as verified
},
}),
]);
Expand Down
10 changes: 2 additions & 8 deletions apps/web/app/app.dub.co/(auth)/login/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const errorCodes = {
"exceeded-login-attempts":
"Account has been locked due to too many login attempts. Please contact support to unlock your account.",
"too-many-login-attempts": "Too many login attempts. Please try again later.",
"email-not-verified": "Please verify your email address.",
};

const LoginFormContext = createContext<{
Expand Down Expand Up @@ -388,20 +389,13 @@ const SignInWithEmail = () => {

// Handle errors
if (!res.ok && res.error) {
if (res.error === "email-not-verified") {
router.push(
`/register/verify-email?email=${encodeURIComponent(email)}`,
);
return;
}

if (errorCodes[res.error]) {
toast.error(errorCodes[res.error]);
} else {
toast.error(res.error);
}
setClickedMethod(undefined);

setClickedMethod(undefined);
return;
}

Expand Down
1 change: 0 additions & 1 deletion apps/web/lib/middleware/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default async function AppMiddleware(req: NextRequest) {
path !== "/login" &&
path !== "/forgot-password" &&
path !== "/register" &&
path !== "/register/verify-email" &&
path !== "/auth/saml" &&
!path.startsWith("/auth/reset-password/")
) {
Expand Down
Loading