MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / handleAuth

Function handleAuth

frontend/src/app/auth/oauth-callback/page.tsx:14–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 };

Callers 1

OAuthCallbackPageFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected