From 6018440126ac989d9a14d0c5d0eacbe1fa0cf448 Mon Sep 17 00:00:00 2001 From: KiranRajeev-KV Date: Sun, 28 Dec 2025 04:02:21 +0530 Subject: [PATCH 1/5] fix: update backend URL in .env.example for correct API endpoint --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 4a84447..40d1099 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -NEXT_PUBLIC_BACKEND_URL="http://127.0.0.1:9000/api/v1" +NEXT_PUBLIC_BACKEND_URL="http://127.0.0.1:9000/woc/api/v1" From b01d2b0442334f14334ac20c126b1768ee7781e2 Mon Sep 17 00:00:00 2001 From: KiranRajeev-KV Date: Sun, 28 Dec 2025 04:02:48 +0530 Subject: [PATCH 2/5] ref: update AuthUser properties to camelCase and rename setUser to setTokens --- app/store/useAuthStore.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/store/useAuthStore.ts b/app/store/useAuthStore.ts index b4caa70..d2a9a76 100644 --- a/app/store/useAuthStore.ts +++ b/app/store/useAuthStore.ts @@ -2,16 +2,22 @@ import { create } from 'zustand'; import { persist } from 'zustand/middleware'; export interface AuthUser { - access_token: string; - refresh_token: string; - github_username: string; + accessToken: string; + refreshToken: string; + githubUsername: string; email: string; bounty: number; } export interface AuthState { user: AuthUser | null; - setUser: (user: AuthUser) => void; + setTokens: (tokens: { + accessToken: string; + refreshToken: string; + githubUsername: string; + email: string; + bounty: number; + }) => void; clearUser: () => void; } @@ -19,7 +25,22 @@ export const useAuthStore = create()( persist( (set) => ({ user: null, - setUser: (user) => set({ user }), + setTokens: ({ + accessToken, + refreshToken, + githubUsername, + email, + bounty, + }) => + set(() => ({ + user: { + accessToken, + refreshToken, + githubUsername, + email, + bounty, + }, + })), clearUser: () => set({ user: null }), }), { From 5e6aa0dae4e79725f92a3e2f72226a79c9f249f8 Mon Sep 17 00:00:00 2001 From: KiranRajeev-KV Date: Sun, 28 Dec 2025 04:03:20 +0530 Subject: [PATCH 3/5] ref: update user properties to camelCase and replace setUser with setTokens in auth flow --- app/auth/callback/page.tsx | 70 ++++++------------- app/components/Navbar.tsx | 18 ++--- .../dashboard-components/leaderboard.tsx | 6 +- .../GameAchivementSystem.tsx | 2 +- app/lib/api.ts | 10 +-- app/login/page.tsx | 11 +-- app/page.tsx | 15 ++-- app/profile/[github_username]/page.tsx | 6 +- 8 files changed, 57 insertions(+), 81 deletions(-) diff --git a/app/auth/callback/page.tsx b/app/auth/callback/page.tsx index f76976d..23ab0fd 100644 --- a/app/auth/callback/page.tsx +++ b/app/auth/callback/page.tsx @@ -1,69 +1,43 @@ 'use client'; +import { useAuthStore } from '@/app/store/useAuthStore'; import { useRouter, useSearchParams } from 'next/navigation'; -import { useEffect } from 'react'; -import { Suspense } from 'react'; -import toast from 'react-hot-toast'; -import { useAuthStore } from '../../store/useAuthStore'; +import { Suspense, useEffect } from 'react'; -function AuthCallbackContent() { - const router = useRouter(); +const CallbackContent = () => { const searchParams = useSearchParams(); - const { setUser } = useAuthStore(); + const router = useRouter(); + const { setTokens } = useAuthStore(); useEffect(() => { const accessToken = searchParams.get('access_token'); const refreshToken = searchParams.get('refresh_token'); const githubUsername = searchParams.get('github_username'); const email = searchParams.get('email'); - const bountyStr = searchParams.get('bounty'); - const error = searchParams.get('error'); - - if (error) { - toast.error('Authentication Error'); - router.push('/'); - return; - } if (accessToken && refreshToken && githubUsername && email) { - // update the auth store with the new data - setUser({ - access_token: accessToken, - refresh_token: refreshToken, - github_username: githubUsername, - email: email, - bounty: bountyStr ? Number.parseInt(bountyStr) : 0, + setTokens({ + accessToken, + refreshToken, + githubUsername, + email, + bounty: 0, }); - - toast.success('GitHub account linked successfully!'); router.push('/'); } else { - router.push('/'); + router.push('/login'); } - }, [searchParams, setUser, router]); - return ( -
-
-
-

Finishing setup...

-
-
- ); -} + }, [searchParams, router, setTokens]); -export default function AuthCallback() { + return
Loading...
; +}; + +const AuthCallbackPage = () => { return ( - -
-
-

Finishing setup...

-
-
- } - > - + Loading...
}> + ); -} +}; + +export default AuthCallbackPage; diff --git a/app/components/Navbar.tsx b/app/components/Navbar.tsx index bffce55..037a55c 100644 --- a/app/components/Navbar.tsx +++ b/app/components/Navbar.tsx @@ -19,7 +19,7 @@ const Navbar = () => { const router = useRouter(); const user = useAuthStore((state) => state.user); const clearUser = useAuthStore((state) => state.clearUser); - const github_username = user?.github_username || ''; + const github_username = user?.githubUsername || ''; const { classes } = useTheme(); useEffect(() => { @@ -164,12 +164,12 @@ const Navbar = () => { className="cursor-pointer flex items-center gap-2 rounded-l-full bg-white px-2 py-1 text-base font-semibold text-gray-800 shadow transition hover:shadow-md focus:outline-none focus:ring-2 focus:ring-blue-200" > {user.github_username} - {user.github_username} + {user.githubUsername}
@@ -221,15 +221,17 @@ const Navbar = () => {
); -} - - return
Loading...
; }; const AuthCallbackPage = () => { From 2dc6d6894178c2f2b7d02356a11d92e342873a1d Mon Sep 17 00:00:00 2001 From: Adithya Menon R Date: Thu, 1 Jan 2026 03:48:35 +0530 Subject: [PATCH 5/5] fixed refactoring --- app/components/Navbar.tsx | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/components/Navbar.tsx b/app/components/Navbar.tsx index f980eca..4c98ca8 100644 --- a/app/components/Navbar.tsx +++ b/app/components/Navbar.tsx @@ -20,7 +20,7 @@ const Navbar = () => { const router = useRouter(); const user = useAuthStore((state) => state.user); const clearUser = useAuthStore((state) => state.clearUser); - const github_username = user?.githubUsername || ''; + const githubUsername = user?.githubUsername || ''; const { classes } = useTheme(); useEffect(() => { @@ -162,8 +162,8 @@ const Navbar = () => { @@ -235,8 +235,8 @@ const Navbar = () => {