Move redirect to outside try..catch block

This commit is contained in:
Sianida26 2024-01-22 01:45:07 +07:00
parent 24eefcc253
commit c27305dc0f
2 changed files with 7 additions and 3 deletions

View File

@ -87,9 +87,11 @@ export default async function createUser(formData: FormData){
const token = createJwtToken({ id: user.id }); const token = createJwtToken({ id: user.id });
cookies().set("token", token); cookies().set("token", token);
redirect("/dashboard");
} catch (e: unknown) { } catch (e: unknown) {
// Handle unexpected errors // Handle unexpected errors
console.error(e)
//@ts-ignore
console.log(e.message)
return { return {
success: false, success: false,
error: { error: {
@ -97,4 +99,6 @@ export default async function createUser(formData: FormData){
}, },
}; };
} }
redirect("/dashboard");
} }

View File

@ -54,8 +54,6 @@ export default async function signIn(prevState: any, rawFormData: FormData) {
const token = createJwtToken({ id: user.id }); const token = createJwtToken({ id: user.id });
cookies().set("token", token); cookies().set("token", token);
redirect("/dashboard");
} catch (e: unknown) { } catch (e: unknown) {
// Custom error handling for authentication errors // Custom error handling for authentication errors
if (e instanceof BaseError) { if (e instanceof BaseError) {
@ -87,4 +85,6 @@ export default async function signIn(prevState: any, rawFormData: FormData) {
}, },
}; };
} }
redirect("/dashboard");
} }