Skip to content

Commit

Permalink
feat: cookies 함수 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
bottlewook committed Feb 29, 2024
1 parent a136a0c commit 455e8c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/types/cookies.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface CookieGetOptions {
doNotParse?: boolean;
doNotUpdate?: boolean;
}
export interface CookieSetOptions {
path?: string;
expires?: Date;
maxAge?: number;
domain?: string;
secure?: boolean;
httpOnly?: boolean;
sameSite?: boolean | 'none' | 'lax' | 'strict';
}
export interface CookieChangeOptions {
name: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value?: any;
options?: CookieSetOptions;
}
18 changes: 18 additions & 0 deletions src/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Cookies } from 'react-cookie';

import { CookieGetOptions, CookieSetOptions } from '@/types/cookies.type';

const cookies = new Cookies();

export const setCookie = (name: string, value: string, options?: CookieSetOptions) => {
return cookies.set(name, value, { ...options });
};

export const getCookie = (name: string, options?: CookieGetOptions) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return cookies.get(name, options);
};

export const removeCookie = (name: string, options?: CookieSetOptions) => {
return cookies.remove(name, options);
};

0 comments on commit 455e8c6

Please sign in to comment.