Add user login, signup, and session.

This commit is contained in:
Hannah dagemark 2026-09-02 21:39:39 +02:00
commit f5466faa70
6 changed files with 101 additions and 36 deletions

View file

@ -0,0 +1,32 @@
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { createUser, loginUser } from "../api/helpers/users";
import { Token } from "../api/types";
export async function login(formData: FormData) {
"use server";
const token = await loginUser(formData);
await createSession(token);
redirect("/admin/overview");
}
export async function signup(formData: FormData) {
// Technically same code as login for now but will do different stuff with it later so separating it early on
"use server";
const token = await createUser(formData);
await createSession(token);
redirect("/admin/overview");
}
export async function createSession(token: Token) {
const access_token = token.access_token;
const cookieStore = await cookies();
cookieStore.set("access_token", access_token, {
httpOnly: true,
secure: true,
sameSite: "lax",
path: "/",
});
}