mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 03:51:12 -05:00
Refactor: Implement email confirmation for password auth
This commit is contained in:
@@ -18,7 +18,7 @@ import type { OAuthProvider } from '@/types/identity';
|
||||
interface PasswordSetupDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSuccess: (email?: string) => void;
|
||||
onSuccess: (email?: string, needsConfirmation?: boolean) => void;
|
||||
provider?: OAuthProvider;
|
||||
mode?: 'standalone' | 'disconnect';
|
||||
}
|
||||
@@ -61,8 +61,8 @@ export function PasswordSetupDialog({
|
||||
setConfirmPassword('');
|
||||
|
||||
if (result.needsRelogin && result.email) {
|
||||
// Pass email to parent for redirect handling
|
||||
onSuccess(result.email);
|
||||
// Pass email and confirmation flag to parent for redirect handling
|
||||
onSuccess(result.email, result.needsEmailConfirmation);
|
||||
} else {
|
||||
onSuccess();
|
||||
}
|
||||
|
||||
@@ -122,14 +122,22 @@ export function SecurityTab() {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePasswordSetupSuccess = async (email?: string) => {
|
||||
const handlePasswordSetupSuccess = (email?: string, needsConfirmation?: boolean) => {
|
||||
if (email) {
|
||||
// Password was set, user was logged out, needs to sign in with email/password
|
||||
toast({
|
||||
title: 'Password Set Successfully',
|
||||
description: 'Please sign in with your email and password to complete setup.',
|
||||
duration: 6000,
|
||||
});
|
||||
// Password was set, user was logged out, needs to confirm email
|
||||
if (needsConfirmation) {
|
||||
toast({
|
||||
title: 'Check Your Email',
|
||||
description: 'A confirmation link has been sent to your email. Click it to activate password authentication, then sign in.',
|
||||
duration: 10000,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
title: 'Password Set Successfully',
|
||||
description: 'Please sign in with your email and password to complete setup.',
|
||||
duration: 6000,
|
||||
});
|
||||
}
|
||||
|
||||
// Redirect to auth page with email pre-filled
|
||||
navigate(`/auth?email=${encodeURIComponent(email)}&message=complete-password-setup`);
|
||||
@@ -137,16 +145,15 @@ export function SecurityTab() {
|
||||
// Normal password change flow (user already had email identity)
|
||||
setAddingPassword(true);
|
||||
|
||||
try {
|
||||
await loadIdentities();
|
||||
loadIdentities().then(() => {
|
||||
toast({
|
||||
title: 'Password Updated',
|
||||
description: 'Your password has been successfully updated.',
|
||||
});
|
||||
setPasswordSetupProvider(null);
|
||||
} finally {
|
||||
}).finally(() => {
|
||||
setAddingPassword(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -185,7 +192,7 @@ export function SecurityTab() {
|
||||
<PasswordSetupDialog
|
||||
open={!!passwordSetupProvider}
|
||||
onOpenChange={(open) => !open && setPasswordSetupProvider(null)}
|
||||
onSuccess={handlePasswordSetupSuccess}
|
||||
onSuccess={(email, needsConfirmation) => handlePasswordSetupSuccess(email, needsConfirmation)}
|
||||
provider={passwordSetupProvider}
|
||||
mode={addPasswordMode}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user