Skip to content

Commit

Permalink
Merge pull request #37 from trandaison/feat/move_to_cookie_es
Browse files Browse the repository at this point in the history
feat: Switch to cookie-es
  • Loading branch information
trandaison authored Oct 8, 2024
2 parents b749552 + ddc694a commit e43ddc4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 36 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"@nuxt/kit": "^3.8.2",
"@nuxtjs/i18n": "^8.2.0",
"@pinia/nuxt": "^0.5.1",
"cookie-es": "^1.2.2",
"defu": "^6.1.3",
"jwt-decode": "^3.1.2",
"jwt-decode": "^4.0.0",
"lodash-es": "^4.17.21",
"ofetch": "^1.3.3",
"pathe": "^1.1.1",
Expand All @@ -51,11 +52,9 @@
"@nuxt/module-builder": "^0.8.4",
"@nuxt/schema": "^3.8.2",
"@nuxt/test-utils": "^3.12.0",
"@types/cookie": "^0.6.0",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.10.3",
"changelogen": "^0.5.5",
"cookie": "^0.6.0",
"eslint": "^8.55.0",
"nuxt": "^3.13.2",
"vitepress": "^1.2.3",
Expand Down
41 changes: 14 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/services/AuthStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jwtDecode from "jwt-decode";
import { jwtDecode } from "jwt-decode";
import { storeToRefs } from "pinia";
import type { AuthConfig, User, AuthTokens } from "../../types";
import { useAuthStore } from "../store/auth";
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/utils/UniversalCookie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRequestEvent } from '#imports';
import cookie, { type CookieSerializeOptions } from 'cookie';
import { parse, serialize, type CookieSerializeOptions } from 'cookie-es';
import { setCookie as _setCookie, deleteCookie } from 'h3';

export default class UniversalCookie {
Expand All @@ -14,7 +14,7 @@ export default class UniversalCookie {
constructor() {
this.requestEvent = useRequestEvent();
if (import.meta.server && this.requestEvent) {
this.cache = cookie.parse(this.requestEvent?.headers?.get('cookie') || '');
this.cache = parse(this.requestEvent?.headers?.get('cookie') || '');
}
}

Expand All @@ -23,7 +23,7 @@ export default class UniversalCookie {
return this.requestEvent ? this.cache![name] : undefined;
}

return cookie.parse(document.cookie)[name];
return parse(document.cookie)[name];
}

setCookie(name: string, value: string | null, options: CookieSerializeOptions = {}) {
Expand All @@ -37,7 +37,7 @@ export default class UniversalCookie {
_setCookie(this.requestEvent, name, value, options);
this.cache![name] = value;
} else {
document.cookie = cookie.serialize(name, value, options);
document.cookie = serialize(name, value, options);
}
}

Expand All @@ -47,7 +47,7 @@ export default class UniversalCookie {
deleteCookie(this.requestEvent, name, options);
delete this.cache![name];
} else {
document.cookie = cookie.serialize(name, '', { ...options, maxAge: -1 });
document.cookie = serialize(name, '', { ...options, maxAge: -1 });
}
}
}

0 comments on commit e43ddc4

Please sign in to comment.