This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Showing
5 changed files
with
97 additions
and
80 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
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,31 @@ | ||
import type { NuxtAppOptions } from '@nuxt/types' | ||
|
||
type CookieValue = string | Record<string, boolean | string | undefined> | ||
|
||
export const useCookies = <T extends CookieValue>( | ||
app: NuxtAppOptions, | ||
name: string | ||
) => { | ||
/** | ||
* Sets the cookie with the `value`, using the useCookie's `name`. | ||
* | ||
* @param value - if not a string, this value is converted to string using | ||
* `JSON.stringify`. | ||
*/ | ||
const setCookie = (value: T) => { | ||
const cookieValue = | ||
typeof value === 'string' ? value : JSON.stringify(value) | ||
|
||
app.$cookies.set(name, cookieValue, { sameSite: true }) | ||
} | ||
|
||
const getCookie = (): string | undefined => { | ||
return app.$cookies.get(name) | ||
} | ||
|
||
return { | ||
setCookie, | ||
getCookie, | ||
} | ||
} | ||
export default useCookies |
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
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
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