-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a136a0c
commit 455e8c6
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |