Skip to content

Commit 86a2a4f

Browse files
author
Boopathi
committed
fix: send email verification after registration and clean up Google sign-in flow
1 parent b5896f6 commit 86a2a4f

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/components/auth/signup-modal.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
GoogleAuthProvider,
1717
signInWithPopup,
1818
createUserWithEmailAndPassword,
19-
updateProfile
19+
updateProfile,
20+
sendEmailVerification
2021
} from "firebase/auth";
2122
import { useRouter } from "next/navigation";
2223

@@ -75,6 +76,8 @@ export default function SignupModal({ isOpen, setIsOpen }: SignupModalProps) {
7576
const userCredential = await createUserWithEmailAndPassword(auth, values.email, values.password);
7677
// Optionally update display name
7778
await updateProfile(userCredential.user, { displayName: values.name });
79+
// Send email verification
80+
await sendEmailVerification(userCredential.user);
7881
toast({
7982
title: "Registration Successful",
8083
description: "Your account has been created. Please check your email to verify your account.",
@@ -103,24 +106,11 @@ export default function SignupModal({ isOpen, setIsOpen }: SignupModalProps) {
103106
return;
104107
}
105108
const authProvider = new GoogleAuthProvider();
106-
107109
try {
108110
const result = await signInWithPopup(auth, authProvider);
109-
const idToken = await result.user.getIdToken();
110-
const response = await fetch(`${API_BASE_URL}/api/login`, {
111-
method: 'POST',
112-
headers: { 'Authorization': `Bearer ${idToken}` },
113-
});
114-
const data = await response.json();
115-
if (!response.ok) throw new Error(data.error || "Backend login failed");
116-
117-
if (data.action === 'complete-profile') {
118-
setIsOpen(false);
119-
router.push(`/complete-profile?token=${data.token}`);
120-
} else {
121-
toast({ title: "Login Successful", description: `Welcome back, ${data.name}!` });
122-
window.location.reload();
123-
}
111+
toast({ title: "Login Successful", description: `Welcome, ${result.user.displayName || result.user.email}!` });
112+
setIsOpen(false);
113+
// Optionally update UI or redirect
124114
} catch (error: any) {
125115
let description = error.message || 'An error occurred while signing in.';
126116
if (error.code === 'auth/invalid-api-key' || error.message.includes('api-key-not-valid')) {

0 commit comments

Comments
 (0)