mirror of https://github.com/kortix-ai/suna.git
fix login redirect
This commit is contained in:
parent
b3666e8aad
commit
6623e87ea9
|
@ -1,5 +1,3 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
|
|
|
@ -27,7 +27,8 @@ export async function signIn(prevState: any, formData: FormData) {
|
|||
return { message: error.message || "Could not authenticate user" };
|
||||
}
|
||||
|
||||
return redirect(returnUrl || "/dashboard");
|
||||
// Use client-side navigation instead of server-side redirect
|
||||
return { success: true, redirectTo: returnUrl || "/dashboard" };
|
||||
}
|
||||
|
||||
export async function signUp(prevState: any, formData: FormData) {
|
||||
|
@ -73,7 +74,8 @@ export async function signUp(prevState: any, formData: FormData) {
|
|||
return { message: "Account created! Check your email to confirm your registration." };
|
||||
}
|
||||
|
||||
return redirect(returnUrl || "/dashboard");
|
||||
// Use client-side navigation instead of server-side redirect
|
||||
return { success: true, redirectTo: returnUrl || "/dashboard" };
|
||||
}
|
||||
|
||||
export async function forgotPassword(prevState: any, formData: FormData) {
|
||||
|
|
|
@ -104,7 +104,16 @@ function LoginContent() {
|
|||
} else {
|
||||
formData.append("returnUrl", "/dashboard");
|
||||
}
|
||||
return signIn(prevState, formData);
|
||||
const result = await signIn(prevState, formData);
|
||||
|
||||
// Check for success and redirectTo properties
|
||||
if (result && typeof result === 'object' && 'success' in result && result.success && 'redirectTo' in result) {
|
||||
// Use window.location for hard navigation to avoid stale state
|
||||
window.location.href = result.redirectTo as string;
|
||||
return null; // Return null to prevent normal form action completion
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const handleSignUp = async (prevState: any, formData: FormData) => {
|
||||
|
@ -121,6 +130,13 @@ function LoginContent() {
|
|||
|
||||
const result = await signUp(prevState, formData);
|
||||
|
||||
// Check for success and redirectTo properties (direct login case)
|
||||
if (result && typeof result === 'object' && 'success' in result && result.success && 'redirectTo' in result) {
|
||||
// Use window.location for hard navigation to avoid stale state
|
||||
window.location.href = result.redirectTo as string;
|
||||
return null; // Return null to prevent normal form action completion
|
||||
}
|
||||
|
||||
// Check if registration was successful but needs email verification
|
||||
if (result && typeof result === 'object' && 'message' in result) {
|
||||
const resultMessage = result.message as string;
|
||||
|
|
|
@ -68,6 +68,9 @@ export default function GoogleSignIn({ returnUrl }: GoogleSignInProps) {
|
|||
try {
|
||||
setIsLoading(true);
|
||||
const supabase = createClient();
|
||||
|
||||
console.log('Starting Google sign in process');
|
||||
|
||||
const { error } = await supabase.auth.signInWithIdToken({
|
||||
provider: 'google',
|
||||
token: response.credential,
|
||||
|
@ -75,10 +78,13 @@ export default function GoogleSignIn({ returnUrl }: GoogleSignInProps) {
|
|||
|
||||
if (error) throw error;
|
||||
|
||||
// Add a small delay before redirecting to ensure localStorage is properly saved
|
||||
console.log('Google sign in successful, preparing redirect to:', returnUrl || "/dashboard");
|
||||
|
||||
// Add a longer delay before redirecting to ensure localStorage is properly saved
|
||||
setTimeout(() => {
|
||||
console.log('Executing redirect now to:', returnUrl || "/dashboard");
|
||||
window.location.href = returnUrl || "/dashboard";
|
||||
}, 100);
|
||||
}, 500); // Increased from 100ms to 500ms
|
||||
} catch (error) {
|
||||
console.error('Error signing in with Google:', error);
|
||||
setIsLoading(false);
|
||||
|
|
Loading…
Reference in New Issue