From ad46bf954ed521280c19a769a3eed29cecab413e Mon Sep 17 00:00:00 2001 From: shafin-r Date: Sat, 16 Aug 2025 17:05:40 +0600 Subject: [PATCH] fix(api): fix api endpoint logic #2 --- app/(auth)/login/page.tsx | 15 ++++++++----- app/(tabs)/home/page.tsx | 47 ++++++++++++++++++++------------------- context/AuthContext.tsx | 3 --- lib/auth.ts | 14 +++++------- types/auth.d.ts | 2 +- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index afe3562..d2c3226 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -10,13 +10,14 @@ import { login } from "@/lib/auth"; import DestructibleAlert from "@/components/DestructibleAlert"; import { useAuth } from "@/context/AuthContext"; import { LoginForm } from "@/types/auth"; +import { CircleAlert } from "lucide-react"; const LoginPage = () => { const router = useRouter(); const { setToken } = useAuth(); const [form, setForm] = useState({ - email: "", + identifier: "", password: "", }); @@ -71,11 +72,11 @@ const LoginPage = () => {
- setForm({ ...form, email: value }) + setForm({ ...form, identifier: value }) } /> { } />
- {error && } +

+ + Your login details will be remembered. +

+
- + */} {/* Performance Summary Section */} diff --git a/context/AuthContext.tsx b/context/AuthContext.tsx index 4cde60c..addebe3 100644 --- a/context/AuthContext.tsx +++ b/context/AuthContext.tsx @@ -59,8 +59,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ useEffect(() => { const initializeAuth = () => { const storedToken = getCookie("authToken"); - console.log("Current pathname:", pathname); - console.log("Stored token:", storedToken); if (storedToken) { setTokenState(storedToken); @@ -69,7 +67,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ pathname === "/login" || pathname === "/register" ) { - console.log("Redirecting to /home"); router.replace("/home"); } } else { diff --git a/lib/auth.ts b/lib/auth.ts index 72e2347..fddf0bb 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,4 +1,6 @@ -export const API_URL = "https://examjam-api.pptx704.com"; +import { LoginForm, RegisterForm } from "@/types/auth"; + +export const API_URL = "https://examjam-backend.omukk.dev"; // Cookie utility function const setCookie = (name: string, value: string | null, days: number = 7) => { @@ -15,12 +17,6 @@ const setCookie = (name: string, value: string | null, days: number = 7) => { } }; -interface AuthForm { - email: string; - password: string; - [key: string]: any; // for flexibility -} - type SetTokenFn = (token: string) => void; // Optional: Create a custom error type to carry extra data @@ -29,7 +25,7 @@ interface APIError extends Error { } export const login = async ( - form: AuthForm, + form: LoginForm, setToken: SetTokenFn ): Promise => { const response = await fetch(`${API_URL}/auth/login`, { @@ -51,7 +47,7 @@ export const login = async ( }; export const register = async ( - form: AuthForm, + form: RegisterForm, setToken: SetTokenFn ): Promise => { const response = await fetch(`${API_URL}/auth/register`, { diff --git a/types/auth.d.ts b/types/auth.d.ts index 0705609..abf69a0 100644 --- a/types/auth.d.ts +++ b/types/auth.d.ts @@ -22,6 +22,6 @@ export interface RegisterForm { } export interface LoginForm { - email: string; + identifier: string; password: string; }