()
| 6 | import { toast } from 'sonner'; |
| 7 | |
| 8 | // Failures land back on the landing page, where the sign-in modal is. They |
| 9 | // used to push /login, which has never been a route in this app — so the one |
| 10 | // thing a user saw after a failed sign-in was a 404. |
| 11 | export default function OAuthCallbackPage() { |
| 12 | const router = useRouter(); |
| 13 | const searchParams = useSearchParams(); |
| 14 | const { login } = useAuthContext(); |
| 15 | |
| 16 | useEffect(() => { |
| 17 | const handleAuth = async () => { |
| 18 | try { |
| 19 | const accessToken = searchParams.get('accessToken'); |
| 20 | const refreshToken = searchParams.get('refreshToken'); |
| 21 | const error = searchParams.get('error'); |
| 22 | |
| 23 | // Handle error cases |
| 24 | if (error) { |
| 25 | console.error('Authentication error:', error); |
| 26 | toast.error('Authentication failed'); |
| 27 | router.push('/'); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | // Check if tokens exist |
| 32 | if (!accessToken || !refreshToken) { |
| 33 | console.error('Missing tokens in callback'); |
| 34 | toast.error('Authentication failed: Missing tokens'); |
| 35 | router.push('/'); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | // Store tokens using the context |
| 40 | login(accessToken, refreshToken); |
| 41 | |
| 42 | // Show success message |
| 43 | toast.success('Logged in successfully!'); |
| 44 | |
| 45 | // Redirect to home or dashboard |
| 46 | router.push('/'); |
| 47 | } catch (error) { |
| 48 | console.error('Error processing authentication:', error); |
| 49 | toast.error('Authentication processing failed'); |
| 50 | router.push('/'); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | handleAuth(); |
| 55 | }, [searchParams, login, router]); |
| 56 | |
| 57 | return ( |
| 58 | <div className="flex h-screen w-full items-center justify-center"> |
| 59 | <div className="text-center p-8 max-w-md rounded-xl bg-background shadow-lg"> |
| 60 | <h1 className="text-2xl font-bold mb-4"> |
| 61 | Completing authentication... |
| 62 | </h1> |
| 63 | <p className="text-muted-foreground mb-4"> |
| 64 | Please wait while we sign you in. |
| 65 | </p> |
nothing calls this directly
no test coverage detected