Skip to content

Commit e43b80c

Browse files
author
Boopathi
committed
fix: prevent 'Invalid State' flash after email verification by showing redirecting spinner
1 parent 7b9bfa8 commit e43b80c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/app/auth/action/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const ActionHandlerContent: React.FC = () => {
114114
const [showResendForm, setShowResendForm] = React.useState(false);
115115
const [info, setInfo] = React.useState<{ email: string; from: 'verifyEmail' | 'resetPassword' } | null>(null);
116116
const [success, setSuccess] = React.useState(false);
117+
const [redirecting, setRedirecting] = React.useState(false);
117118

118119
const form = useForm<PasswordResetValues>({
119120
resolver: zodResolver(passwordResetSchema),
@@ -211,6 +212,7 @@ const ActionHandlerContent: React.FC = () => {
211212

212213
if (success) {
213214
if (info?.from === 'verifyEmail') {
215+
setRedirecting(true);
214216
// After verification, check if profile is complete
215217
(async () => {
216218
try {
@@ -245,6 +247,8 @@ const ActionHandlerContent: React.FC = () => {
245247
description: "Please log in.",
246248
});
247249
router.push('/?action=login&from=verification_success');
250+
} finally {
251+
setRedirecting(false);
248252
}
249253
})();
250254
return null;
@@ -259,6 +263,15 @@ const ActionHandlerContent: React.FC = () => {
259263
}
260264
}
261265

266+
if (redirecting) {
267+
return (
268+
<div className="text-center">
269+
<Loader2 className="h-12 w-12 animate-spin text-primary mx-auto mb-4" />
270+
<p className="text-muted-foreground">Redirecting...</p>
271+
</div>
272+
);
273+
}
274+
262275
if (mode === 'resetPassword' && info) {
263276
return (
264277
<div>

0 commit comments

Comments
 (0)