🧑💻 (dev) add helper for settingup a cookies
This commit is contained in:
@ -5,9 +5,9 @@ import { RegisterInputs } from "../ui/components/ProvisionInput";
|
|||||||
import { ServerRequestCallback } from "@/shared/types/ServerRequestCallback";
|
import { ServerRequestCallback } from "@/shared/types/ServerRequestCallback";
|
||||||
import { generateRandomString } from "@/shared/helper/generateRandomString";
|
import { generateRandomString } from "@/shared/helper/generateRandomString";
|
||||||
import { CallbackFromBackend } from "../types/callbackFromBackend";
|
import { CallbackFromBackend } from "../types/callbackFromBackend";
|
||||||
import { cookies } from "next/headers";
|
|
||||||
import { api } from "@/shared/lib/ky/connector";
|
import { api } from "@/shared/lib/ky/connector";
|
||||||
import { COOKIE_KEYS } from "@/shared/constants/cookie.key";
|
import { COOKIE_KEYS } from "@/shared/constants/cookie.key";
|
||||||
|
import { setCookie } from "@/shared/helper/cookies/set";
|
||||||
|
|
||||||
export const submitRegisterForm = async (
|
export const submitRegisterForm = async (
|
||||||
data: RegisterInputs
|
data: RegisterInputs
|
||||||
@ -37,15 +37,7 @@ export const submitRegisterForm = async (
|
|||||||
.post("users", { json: payload })
|
.post("users", { json: payload })
|
||||||
.json()) as CallbackFromBackend<string>;
|
.json()) as CallbackFromBackend<string>;
|
||||||
|
|
||||||
(await cookies()).set({
|
await setCookie(COOKIE_KEYS.AUTH, callback.data!);
|
||||||
name: COOKIE_KEYS["AUTH"],
|
|
||||||
value: callback.data!,
|
|
||||||
httpOnly: true,
|
|
||||||
secure: process.env.NODE_ENV === "production",
|
|
||||||
path: "/",
|
|
||||||
sameSite: "lax",
|
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
15
shared/helper/cookies/set.ts
Normal file
15
shared/helper/cookies/set.ts
Normal 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),
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user