Skip to content

Commit

Permalink
MODIFY: sign up func no longers set the cookies, users is asked to lo…
Browse files Browse the repository at this point in the history
…gin after signing up
  • Loading branch information
srkuleo committed Aug 28, 2024
1 parent 04a1356 commit 240d18d
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/util/actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,20 @@ export async function signUp(formData: FormData): Promise<AuthActionResponse> {
};
}

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<AuthActionResponse> {
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;
Expand All @@ -133,19 +122,13 @@ export async function login(formData: FormData): Promise<AuthActionResponse> {
});

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, {});
Expand All @@ -157,7 +140,6 @@ export async function login(formData: FormData): Promise<AuthActionResponse> {
);

console.log("User validated, you are logged in!");
return redirect("/workouts");
}

export async function logout() {
Expand Down

0 comments on commit 240d18d

Please sign in to comment.