Skip to content

Commit

Permalink
feat: support secure cookie storage for nuxt sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun committed Sep 14, 2024
1 parent 3d072c9 commit 620aa42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-humans-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@logto/nuxt": major
---

support secure cookie storage for nuxt SDK
19 changes: 9 additions & 10 deletions packages/nuxt/src/runtime/server/event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineEventHandler(async (event) => {
const {
cookieName,
cookieEncryptionKey,
cookieSecure,
fetchUserInfo,
pathnames,
postCallbackRedirectUri,
Expand All @@ -36,17 +37,15 @@ export default defineEventHandler(async (event) => {
}

const url = getRequestURL(event);
const storage = new CookieStorage(
{
cookieKey: cookieName,
encryptionKey: cookieEncryptionKey,
getCookie: (name) => getCookie(event, name),
setCookie: (name, value, options) => {
setCookie(event, name, value, options);
},
const storage = new CookieStorage({
cookieKey: cookieName,
encryptionKey: cookieEncryptionKey,
isSecure: cookieSecure,
getCookie: (name) => getCookie(event, name),
setCookie: (name, value, options) => {
setCookie(event, name, value, options);
},
{ headers: event.headers, url: url.href }
);
});

await storage.init();

Expand Down
8 changes: 8 additions & 0 deletions packages/nuxt/src/runtime/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type LogtoModuleOptions = {
* @see {@link CookieConfig.cookieKey} for the default value.
*/
cookieName?: string;
/**
* Whether the Logto cookie should be secure.
*
* Set this to `true` if you are using https.
*
* @see {@link CookieConfig.isSecure}
*/
cookieSecure?: boolean;
/**
* If Logto should fetch from the [userinfo endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
* in the server side for the `event.context.logtoUser` property (used by `useLogtoUser` composable).
Expand Down

0 comments on commit 620aa42

Please sign in to comment.