Fix login->dashboard transition by waiting for auth to resolve before navigating
cgen-89065b7bc17d40e5a2e36a656eab635f
This commit is contained in:
parent
245802644a
commit
d7dc308cb6
1 changed files with 9 additions and 8 deletions
|
|
@ -37,10 +37,12 @@ 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();
|
||||||
|
|
||||||
// Keep users on the login page; navigate only after successful auth
|
// After auth resolves and a user exists, navigate to dashboard
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// no-op
|
if (user && !loading) {
|
||||||
}, []);
|
navigate("/dashboard", { replace: true });
|
||||||
|
}
|
||||||
|
}, [user, loading, navigate]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -49,10 +51,10 @@ export default function Login() {
|
||||||
try {
|
try {
|
||||||
if (isSignUp) {
|
if (isSignUp) {
|
||||||
await signUp(email, password, {
|
await signUp(email, password, {
|
||||||
id: "", // Will be set by Supabase
|
id: "",
|
||||||
full_name: fullName,
|
full_name: fullName,
|
||||||
user_type: "game_developer", // Default, can be changed in onboarding
|
user_type: "game_developer",
|
||||||
username: email.split("@")[0], // Generate username from email
|
username: email.split("@")[0],
|
||||||
});
|
});
|
||||||
toastSuccess({
|
toastSuccess({
|
||||||
title: "Account created!",
|
title: "Account created!",
|
||||||
|
|
@ -62,8 +64,7 @@ export default function Login() {
|
||||||
setIsSignUp(false);
|
setIsSignUp(false);
|
||||||
} else {
|
} else {
|
||||||
await signIn(email, password);
|
await signIn(email, password);
|
||||||
// Navigate immediately; Dashboard will handle profile/onboarding state
|
// Do not navigate immediately; wait for auth state to update
|
||||||
navigate("/dashboard", { replace: true });
|
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Authentication error:", error);
|
console.error("Authentication error:", error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue