Update user routing, added user authorization with JWT cookie management
This commit is contained in:
parent
662b26ad47
commit
f055e77eea
7 changed files with 97 additions and 10 deletions
|
|
@ -9,7 +9,7 @@ export async function login(formData: FormData) {
|
|||
"use server";
|
||||
const token = await loginUser(formData);
|
||||
await createSession(token);
|
||||
redirect("/admin/overview");
|
||||
redirect("/Admin/Overview");
|
||||
}
|
||||
|
||||
export async function signup(formData: FormData) {
|
||||
|
|
@ -17,7 +17,7 @@ export async function signup(formData: FormData) {
|
|||
"use server";
|
||||
const token = await createUser(formData);
|
||||
await createSession(token);
|
||||
redirect("/admin/overview");
|
||||
redirect("/Admin/Overview");
|
||||
}
|
||||
|
||||
export async function createSession(token: Token) {
|
||||
|
|
@ -26,8 +26,16 @@ export async function createSession(token: Token) {
|
|||
|
||||
cookieStore.set("access_token", access_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSessionToken() {
|
||||
const cookieStore = await cookies();
|
||||
console.log(cookieStore.getAll());
|
||||
const token = cookieStore.get("access_token")?.value;
|
||||
|
||||
return token ? token : null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue