🧑‍💻 (dev) add helper for settingup a cookies

This commit is contained in:
2025-10-13 10:07:33 +07:00
parent 273db57e7b
commit 35b777e636
2 changed files with 17 additions and 10 deletions

View File

@ -5,9 +5,9 @@ import { RegisterInputs } from "../ui/components/ProvisionInput";
import { ServerRequestCallback } from "@/shared/types/ServerRequestCallback";
import { generateRandomString } from "@/shared/helper/generateRandomString";
import { CallbackFromBackend } from "../types/callbackFromBackend";
import { cookies } from "next/headers";
import { api } from "@/shared/lib/ky/connector";
import { COOKIE_KEYS } from "@/shared/constants/cookie.key";
import { setCookie } from "@/shared/helper/cookies/set";
export const submitRegisterForm = async (
data: RegisterInputs
@ -37,15 +37,7 @@ export const submitRegisterForm = async (
.post("users", { json: payload })
.json()) as CallbackFromBackend<string>;
(await cookies()).set({
name: COOKIE_KEYS["AUTH"],
value: callback.data!,
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
sameSite: "lax",
maxAge: 60 * 60 * 24 * 7,
});
await setCookie(COOKIE_KEYS.AUTH, callback.data!);
return {
success: true,

View File

@ -0,0 +1,15 @@
"use server";
import { cookies } from "next/headers";
export const setCookie = async (name: string, value: string, sec?: number) => {
(await cookies()).set({
name,
value,
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
sameSite: "lax",
maxAge: sec || Number(process.env.SESSION_EXPIRE),
});
};