Skip to content

Commit ba527eb

Browse files
arbrandesclaude
andcommitted
refactor: simplify onSuccess redirect logic in login and registration
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4ff413c commit ba527eb

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

src/login/LoginPage.jsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ const LoginPage = ({
6868
});
6969
const { mutate: loginUser, isPending: isLoggingIn } = useLogin({
7070
onSuccess: async (data) => {
71-
if (localNextPath) {
71+
const redirectUrl = localNextPath || data.redirectUrl || '';
72+
if (redirectUrl.startsWith('/')) {
7273
await fetchAuthenticatedUser({ forceRefresh: true });
73-
setLoginResult({ success: true, redirectUrl: localNextPath });
7474
// Hydrate in the background — publishes AUTHENTICATED_USER_CHANGED after
7575
// SPA navigation, so the header picks up the full user profile (avatar, etc.)
7676
hydrateAuthenticatedUser();
77-
} else if (data.redirectUrl?.startsWith('/')) {
78-
await fetchAuthenticatedUser({ forceRefresh: true });
79-
setLoginResult({ success: true, redirectUrl: data.redirectUrl });
80-
hydrateAuthenticatedUser();
81-
} else {
82-
setLoginResult({ success: true, redirectUrl: data.redirectUrl || '' });
8377
}
78+
setLoginResult({ success: true, redirectUrl });
8479
},
8580
onError: (formattedError) => {
8681
setErrorCode(prev => ({

src/register/RegistrationPage.jsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,14 @@ const RegistrationPage = (props) => {
110110
const backendRegistrationError = registrationError;
111111
const registrationMutation = useRegistration({
112112
onSuccess: async (data) => {
113-
if (localNextPath) {
113+
const redirectUrl = localNextPath || data.redirectUrl || '';
114+
if (redirectUrl.startsWith('/')) {
114115
await fetchAuthenticatedUser({ forceRefresh: true });
115-
setRegistrationResult({ ...data, redirectUrl: localNextPath });
116116
// Hydrate in the background — publishes AUTHENTICATED_USER_CHANGED after
117117
// SPA navigation, so the header picks up the full user profile (avatar, etc.)
118118
hydrateAuthenticatedUser();
119-
} else if (data.redirectUrl?.startsWith('/')) {
120-
await fetchAuthenticatedUser({ forceRefresh: true });
121-
setRegistrationResult({ ...data, redirectUrl: data.redirectUrl });
122-
hydrateAuthenticatedUser();
123-
} else {
124-
setRegistrationResult(data);
125119
}
120+
setRegistrationResult({ ...data, redirectUrl });
126121
setRegistrationError({});
127122
},
128123
onError: (errorData) => {

0 commit comments

Comments
 (0)