Skip to content

Commit 9fab076

Browse files
committed
Fix: don't redirect to /signin on callback session failure
When the session API returned a non-ok response, the callback page was sending users to /signin which briefly showed a confusing "Redirecting to sign in..." screen even after a successful OAuth. Now failures surface an inline error with a "Try again" link on the callback page itself, so the /signin page is never shown post-authentication. https://claude.ai/code/session_01U3mwGcNbKKXSb9P6cBEaqa
1 parent f28c611 commit 9fab076

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

  • frontend/src/app/signin/callback

frontend/src/app/signin/callback/page.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
'use client';
22

3-
import { useEffect, Suspense } from 'react';
3+
import { useEffect, useState, Suspense } from 'react';
44
import { useSearchParams, useRouter } from 'next/navigation';
55
import { useUser } from '@/context/UserContext';
66

77
function CallbackInner() {
88
const searchParams = useSearchParams();
99
const router = useRouter();
1010
const { setActiveUser, confirmApproved } = useUser();
11+
const [errorMsg, setErrorMsg] = useState<string | null>(null);
1112

1213
useEffect(() => {
1314
const userId = searchParams.get('user_id');
@@ -31,15 +32,50 @@ function CallbackInner() {
3132
if (res.ok) {
3233
confirmApproved();
3334
router.replace('/dashboard');
35+
} else if (res.status === 403) {
36+
router.replace('/pending');
3437
} else {
35-
router.replace('/signin');
38+
setErrorMsg('Unable to complete sign-in. Please try again.');
3639
}
40+
}).catch(() => {
41+
setErrorMsg('Unable to reach the server. Please try again.');
3742
});
3843
} else {
39-
router.replace('/signin');
44+
setErrorMsg('Sign-in failed. Please try again.');
4045
}
4146
}, []); // eslint-disable-line react-hooks/exhaustive-deps
4247

48+
if (errorMsg) {
49+
return (
50+
<div style={{
51+
minHeight: '100vh',
52+
display: 'flex',
53+
alignItems: 'center',
54+
justifyContent: 'center',
55+
flexDirection: 'column',
56+
gap: '16px',
57+
background: '#f0f5f0',
58+
padding: '24px',
59+
}}>
60+
<p style={{ color: '#374151', fontSize: '15px', textAlign: 'center' }}>{errorMsg}</p>
61+
<a
62+
href="/api/auth/google"
63+
style={{
64+
padding: '10px 24px',
65+
background: '#1a5c2a',
66+
color: '#fff',
67+
borderRadius: '8px',
68+
fontSize: '14px',
69+
fontWeight: 500,
70+
textDecoration: 'none',
71+
}}
72+
>
73+
Try again
74+
</a>
75+
</div>
76+
);
77+
}
78+
4379
return (
4480
<div style={{
4581
minHeight: '100vh',

0 commit comments

Comments
 (0)