Stop auto-redirect on /login and navigate after successful sign-in
cgen-68ff003f276c402782db62ac80b4d144
This commit is contained in:
parent
f34a6495d5
commit
cc7bd12a0d
1 changed files with 10 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useNavigate, Link } from "react-router-dom";
|
import { useNavigate, Link } from "react-router-dom";
|
||||||
|
import { aethexUserService } from "@/lib/aethex-database-adapter";
|
||||||
import { useAuth } from "@/contexts/AuthContext";
|
import { useAuth } from "@/contexts/AuthContext";
|
||||||
import { useAethexToast } from "@/hooks/use-aethex-toast";
|
import { useAethexToast } from "@/hooks/use-aethex-toast";
|
||||||
import Layout from "@/components/Layout";
|
import Layout from "@/components/Layout";
|
||||||
|
|
@ -36,16 +37,10 @@ export default function Login() {
|
||||||
const { signIn, signUp, signInWithOAuth, user, loading, profile } = useAuth();
|
const { signIn, signUp, signInWithOAuth, user, loading, profile } = useAuth();
|
||||||
const { success: toastSuccess, error: toastError } = useAethexToast();
|
const { success: toastSuccess, error: toastError } = useAethexToast();
|
||||||
|
|
||||||
// Redirect if already logged in
|
// Keep users on the login page; navigate only after successful auth
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user && !loading) {
|
// no-op
|
||||||
if (profile) {
|
}, []);
|
||||||
navigate("/dashboard", { replace: true });
|
|
||||||
} else {
|
|
||||||
navigate("/onboarding", { replace: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [user, profile, loading, navigate]);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -67,7 +62,12 @@ export default function Login() {
|
||||||
setIsSignUp(false);
|
setIsSignUp(false);
|
||||||
} else {
|
} else {
|
||||||
await signIn(email, password);
|
await signIn(email, password);
|
||||||
// Navigation is handled by the auth redirect effect based on profile existence
|
const current = await aethexUserService.getCurrentUser();
|
||||||
|
if (current) {
|
||||||
|
navigate("/dashboard", { replace: true });
|
||||||
|
} else {
|
||||||
|
navigate("/onboarding", { replace: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Authentication error:", error);
|
console.error("Authentication error:", error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue