From 2a74a3e42bbeb7a023744296c170b6fda2a32e34 Mon Sep 17 00:00:00 2001 From: Denys Dinkevych Date: Mon, 18 Nov 2024 13:41:21 +0200 Subject: [PATCH] Update AuthContext.tsx --- src/contexts/AuthContext.tsx | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 5e8fe3f..98de35c 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -59,7 +59,6 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { ); } - useEffect(() => { const handleCallback = async () => { const code = new URLSearchParams(window.location.search).get('code'); @@ -78,24 +77,14 @@ useEffect(() => { } const data = await response.json(); - if (data.access_token) { localStorage.setItem('github_access_token', data.access_token); - // Fetch user information - const userResponse = await fetch('https://api.github.com/user', { - headers: { - Authorization: `Bearer ${data.access_token}`, - }, - }); - - const user = await userResponse.json(); - console.log('Authenticated user:', user); - - // Redirect to the home screen after successful authentication - window.history.replaceState({}, document.title, '/'); // Remove `code` from the URL - } else if (data.error) { - console.error('Authentication error:', data.error_description || 'Authentication failed'); + // Remove the code from the URL and redirect to home + window.history.replaceState({}, document.title, '/'); + window.location.href = '/'; // Fallback + } else { + console.error('Authentication failed: No access token returned'); } } catch (error) { console.error('Authentication error:', error);