From 8c97929bd026b60f6629c0fd8ddab6a8d349a564 Mon Sep 17 00:00:00 2001 From: chundawat-h Date: Mon, 1 Jun 2026 17:06:29 +0530 Subject: [PATCH 1/2] revert: undo non-signin UI/log changes; preserve login hydration fixes --- src/app/context/AuthContext.tsx | 27 ++++++++++++++++++--------- src/app/login/page.tsx | 30 +++++++++++++++++++----------- test-results/.last-run.json | 4 +--- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/app/context/AuthContext.tsx b/src/app/context/AuthContext.tsx index b686e4d..2f8cda4 100644 --- a/src/app/context/AuthContext.tsx +++ b/src/app/context/AuthContext.tsx @@ -83,7 +83,7 @@ interface AuthState { refreshToken: string | null; isLoading: boolean; login: (email: string, password: string) => Promise<{ success: boolean; error?: string }>; - signup: (email: string, password: string, fullName: string, role: string) => Promise<{ success: boolean; error?: string }>; + signup: (email: string, password: string, fullName: string, role: string) => Promise<{ success: boolean; error?: string; confirmationRequired?: boolean }>; loginWithGoogle: () => Promise<{ success: boolean; error?: string }>; logout: () => void; fetchWithAuth: (url: string, options?: RequestInit) => Promise; @@ -308,14 +308,21 @@ export function AuthProvider({ children }: { children: ReactNode }) { } const { tokens, user: userProfile } = json.data; - setToken(tokens.access_token); - setRefreshToken(tokens.refresh_token); - setUser(userProfile); - if (typeof window !== "undefined") { - localStorage.setItem("ozymorlab_token", tokens.access_token); - localStorage.setItem("ozymorlab_refresh_token", tokens.refresh_token); + if (tokens && userProfile) { + setToken(tokens.access_token); + setRefreshToken(tokens.refresh_token); + setUser(userProfile); + if (typeof window !== "undefined") { + localStorage.setItem("ozymorlab_token", tokens.access_token); + localStorage.setItem("ozymorlab_refresh_token", tokens.refresh_token); + } + return { success: true }; } - return { success: true }; + + if (json.data?.user) { + setUser(json.data.user); + } + return { success: true, confirmationRequired: true }; } catch (err: any) { return { success: false, error: err.message || "Failed to register local account" }; } @@ -367,8 +374,10 @@ export function AuthProvider({ children }: { children: ReactNode }) { is_active: true, }); } + return { success: true }; } - return { success: true }; + + return { success: true, confirmationRequired: true }; } catch { return { success: false, error: "Network error. Is Supabase configured correctly?" }; } diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 4d95972..ba114f7 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -1,19 +1,16 @@ "use client"; -import { useState, useEffect, Suspense } from "react"; -import { useRouter, useSearchParams } from "next/navigation"; +import { useState, useEffect } from "react"; +import { useRouter } from "next/navigation"; import Link from "next/link"; import { Eye, EyeOff, ArrowRight, AlertCircle, CheckCircle2, Sparkles } from "lucide-react"; import { AuthProvider, useAuth } from "../context/AuthContext"; function LoginPageContent() { const router = useRouter(); - const searchParams = useSearchParams(); const { login, signup, loginWithGoogle, user, isLoading } = useAuth(); - const [activeTab, setActiveTab] = useState<"login" | "signup">( - searchParams.get("tab") === "signup" ? "signup" : "login" - ); + const [activeTab, setActiveTab] = useState<"login" | "signup">("login"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [fullName, setFullName] = useState(""); @@ -23,6 +20,15 @@ function LoginPageContent() { const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(""); + useEffect(() => { + if (typeof window !== "undefined") { + const params = new URLSearchParams(window.location.search); + if (params.get("tab") === "signup") { + setActiveTab("signup"); + } + } + }, []); + // Redirect if already logged in useEffect(() => { if (!isLoading && user) { @@ -56,8 +62,12 @@ function LoginPageContent() { const result = await signup(email, password, fullName, role); if (result.success) { - setSuccess("Account created! Redirecting..."); - setTimeout(() => router.push("/dashboard"), 800); + if (result.confirmationRequired) { + setSuccess("Registration successful. Check your email and confirm your address before signing in."); + } else { + setSuccess("Account created! Redirecting..."); + setTimeout(() => router.push("/dashboard"), 800); + } } else { setError(result.error || "Signup failed"); } @@ -363,9 +373,7 @@ function LoginPageContent() { export default function LoginPage() { return ( -
}> - -
+
); } diff --git a/test-results/.last-run.json b/test-results/.last-run.json index 957284b..5fca3f8 100644 --- a/test-results/.last-run.json +++ b/test-results/.last-run.json @@ -1,6 +1,4 @@ { "status": "failed", - "failedTests": [ - "70b872a5e72a7b2c7282-d4de8269ab84cb7dd8a5" - ] + "failedTests": [] } \ No newline at end of file From 55ac3f606f462907592cd82c2fa0e68dfba139e7 Mon Sep 17 00:00:00 2001 From: chundawat-h Date: Mon, 1 Jun 2026 17:12:32 +0530 Subject: [PATCH 2/2] fix(login): show panel when already signed in instead of auto-redirect (pre-PR) --- src/app/login/page.tsx | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index ba114f7..cf31131 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -8,7 +8,7 @@ import { AuthProvider, useAuth } from "../context/AuthContext"; function LoginPageContent() { const router = useRouter(); - const { login, signup, loginWithGoogle, user, isLoading } = useAuth(); + const { login, signup, loginWithGoogle, logout, user, isLoading } = useAuth(); const [activeTab, setActiveTab] = useState<"login" | "signup">("login"); const [email, setEmail] = useState(""); @@ -29,12 +29,33 @@ function LoginPageContent() { } }, []); - // Redirect if already logged in - useEffect(() => { - if (!isLoading && user) { - router.push("/dashboard"); - } - }, [user, isLoading, router]); + // If already logged in, show a small informative UI instead of auto-redirecting. + // This prevents the back button from immediately bouncing the user back to dashboard. + if (!isLoading && user) { + return ( +
+
+
+
+
Oz
+ OzymorLab AIOS +
+

Welcome back

+

You are already signed in as {user.email}. Use the buttons to continue.

+
+ + +
+
+
+
+
+

If you want to use a different account, sign out first.

+
+
+
+ ); + } const handleLogin = async (e: React.FormEvent) => { e.preventDefault();