fix(verify-email): prevent redirect loop on failed verification#3082
fix(verify-email): prevent redirect loop on failed verification#3082v1nayG wants to merge 1 commit into
Conversation
Greptile SummaryThis PR fixes two success notification messages in the user verification toggle UI (
Confidence Score: 5/5Safe to merge — the change is a targeted fix to success notification text with no side-effects on API calls, navigation, or data flow. The phone-verification success message was always inverted due to a missing negation; the fix is correct and well-scoped. The email-verification refactoring is functionally equivalent to what it replaced and improves clarity. No logic paths outside the notification strings were touched. No files require special attention. The untouched updateStatus() function in the same file uses a similar post-invalidation store read, but it maps correctly and is not broken. Important Files Changed
Reviews (2): Last reviewed commit: "fix(auth): correct verification alert me..." | Re-trigger Greptile |
| redirect(303, resolve('/')); | ||
| } catch (error) { | ||
| addNotification({ | ||
| type: 'error', | ||
| message: error.message | ||
| }); |
There was a problem hiding this comment.
Redirect is caught and swallowed on success
In SvelteKit, redirect() works by throwing a special Redirect exception internally. Because the call is now inside the try block, the catch (error) block intercepts it before SvelteKit can handle it. Since the catch does not re-throw, the redirect is silently dropped: the user stays on /verify-email, sees a spurious error toast (with error.message being undefined or an internal Redirect string), and the success toast is also shown — all after a successful verification.
The safest fix is to use a flag and call redirect after the try/catch, or re-throw Redirect instances in catch using SvelteKit's isRedirect helper:
import { redirect, isRedirect } from '@sveltejs/kit';
// ...
} catch (error) {
if (isRedirect(error)) throw error;
addNotification({ type: 'error', message: error.message });
}Alternatively, track success outside the try:
let verified = false;
try {
await sdk.forConsole.account.updateVerification({ userId: user, secret });
addNotification({ type: 'success', message: 'Email has been verified', timeout: 10000 });
verified = true;
} catch (error) {
addNotification({ type: 'error', message: error.message });
}
if (verified) redirect(303, resolve('/'));Both updateVerificationEmail and updateVerificationPhone read the user store after invalidation to build the success notification. At that point the store already reflects the new state, so the ternary produces the opposite message — showing 'unverified' after verifying and vice versa. Capture the intended verification state and display label before the API call so the notification always matches the action the user just performed. Also disambiguate the messages to indicate whether the email or phone was verified when the user has both.
07b349e to
98206bf
Compare
Fixes #1392
Both
updateVerificationEmailandupdateVerificationPhoneread the user store afterinvalidate()to build the success notification. At that point the store already reflects the new state, so the ternary produces the opposite message — showing "unverified" after verifying and vice versa.Capture the intended verification state before the API call so the notification always matches the action. Also disambiguate the messages to say "email has been verified" vs "phone has been verified" when the user has both.