From 240d18d0d10795faf61841606943c419cc915452 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Wed, 28 Aug 2024 02:24:08 +0200 Subject: [PATCH] MODIFY: sign up func no longers set the cookies, users is asked to login after signing up --- src/util/actions/auth.ts | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/util/actions/auth.ts b/src/util/actions/auth.ts index 92b98cac..068220bb 100644 --- a/src/util/actions/auth.ts +++ b/src/util/actions/auth.ts @@ -99,31 +99,20 @@ export async function signUp(formData: FormData): Promise { }; } - const session = await lucia.createSession(userId, {}); - const sessionCookie = lucia.createSessionCookie(session.id); - cookies().set( - sessionCookie.name, - sessionCookie.value, - sessionCookie.attributes, - ); - return { status: "success-redirect", message: "Profile created successfully", }; } -export async function login(formData: FormData): Promise { +export async function login(formData: FormData) { const loginRaw = loginSchema.safeParse({ username: formData.get("username"), password: formData.get("password"), }); if (!loginRaw.success) { - return { - status: "error", - errors: loginRaw.error.flatten().fieldErrors, - }; + throw new Error("Invalid credentials"); } const { username, password } = loginRaw.data; @@ -133,19 +122,13 @@ export async function login(formData: FormData): Promise { }); if (!user) { - return { - status: "error", - message: "Incorrect username or password.", - }; + throw new Error("Incorrect username or password"); } const validPassword = await bcrypt.compare(password, user.hashedPassword); if (!validPassword) { - return { - status: "error", - message: "Incorrect username or password.", - }; + throw new Error("Incorrect username or password"); } const session = await lucia.createSession(user.id, {}); @@ -157,7 +140,6 @@ export async function login(formData: FormData): Promise { ); console.log("User validated, you are logged in!"); - return redirect("/workouts"); } export async function logout() {