@logto/nuxt 1.1.5 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.d.mts CHANGED
@@ -4,6 +4,7 @@ export * from '../dist/runtime/utils/types.js';
4
4
  export * from '@logto/node';
5
5
  export { default as LogtoNodeClient } from '@logto/node';
6
6
  export * from '../dist/runtime/utils/constants.js';
7
+ export * from '../dist/runtime/utils/handler.js';
7
8
 
8
9
  declare const logtoModule: NuxtModule<LogtoRuntimeConfigInput>;
9
10
 
package/dist/module.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from '../dist/runtime/utils/types.js';
4
4
  export * from '@logto/node';
5
5
  export { default as LogtoNodeClient } from '@logto/node';
6
6
  export * from '../dist/runtime/utils/constants.js';
7
+ export * from '../dist/runtime/utils/handler.js';
7
8
 
8
9
  declare const logtoModule: NuxtModule<LogtoRuntimeConfigInput>;
9
10
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@logto/nuxt",
3
3
  "configKey": "logto",
4
- "version": "1.1.5",
4
+ "version": "1.2.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -5,6 +5,7 @@ export * from '../dist/runtime/utils/constants.js';
5
5
  export * from '@logto/node';
6
6
  export { default as LogtoNodeClient } from '@logto/node';
7
7
  export * from '../dist/runtime/utils/types.js';
8
+ export * from '../dist/runtime/utils/handler.js';
8
9
 
9
10
  const logtoModule = defineNuxtModule({
10
11
  meta: {
@@ -14,6 +15,7 @@ const logtoModule = defineNuxtModule({
14
15
  defaults,
15
16
  setup(options, nuxt) {
16
17
  const runtimeConfig = defu(
18
+ // eslint-disable-next-line no-restricted-syntax
17
19
  nuxt.options.runtimeConfig.logto,
18
20
  options,
19
21
  {
@@ -1,65 +1,7 @@
1
- import LogtoClient, { CookieStorage } from "@logto/node";
2
- import { trySafe } from "@silverhand/essentials";
3
- import { defineEventHandler, getRequestURL, getCookie, setCookie, sendRedirect } from "h3";
1
+ import { defineEventHandler } from "h3";
4
2
  import { useRuntimeConfig } from "#imports";
5
- import { defaults } from "../utils/constants.js";
3
+ import { logtoEventHandler } from "../utils/handler.js";
6
4
  export default defineEventHandler(async (event) => {
7
5
  const config = useRuntimeConfig(event);
8
- const logtoConfig = config.logto;
9
- const {
10
- cookieName,
11
- cookieEncryptionKey,
12
- cookieSecure,
13
- fetchUserInfo,
14
- pathnames,
15
- postCallbackRedirectUri,
16
- postLogoutRedirectUri,
17
- customRedirectBaseUrl,
18
- signInOptions,
19
- ...clientConfig
20
- } = logtoConfig;
21
- const defaultValueKeys = Object.entries(defaults).filter(([key, value]) => logtoConfig[key] === value).map(([key]) => key);
22
- if (defaultValueKeys.length > 0) {
23
- console.warn(
24
- `The following Logto configuration keys have default values: ${defaultValueKeys.join(
25
- ", "
26
- )}. Please replace them with your own values.`
27
- );
28
- }
29
- const requestUrl = getRequestURL(event);
30
- const url = customRedirectBaseUrl ? new URL(requestUrl.pathname + requestUrl.search + requestUrl.hash, customRedirectBaseUrl) : requestUrl;
31
- const storage = new CookieStorage({
32
- cookieKey: cookieName,
33
- encryptionKey: cookieEncryptionKey,
34
- isSecure: cookieSecure,
35
- getCookie: async (name) => getCookie(event, name),
36
- setCookie: async (name, value, options) => {
37
- setCookie(event, name, value, options);
38
- }
39
- });
40
- await storage.init();
41
- const logto = new LogtoClient(clientConfig, {
42
- navigate: async (url2) => {
43
- await sendRedirect(event, url2, 302);
44
- },
45
- storage
46
- });
47
- if (url.pathname === pathnames.signIn) {
48
- await logto.signIn({
49
- ...signInOptions,
50
- redirectUri: new URL(pathnames.callback, url).href
51
- });
52
- return;
53
- }
54
- if (url.pathname === pathnames.signOut) {
55
- await logto.signOut(new URL(postLogoutRedirectUri, url).href);
56
- return;
57
- }
58
- if (url.pathname === pathnames.callback) {
59
- await logto.handleSignInCallback(url.href);
60
- await sendRedirect(event, postCallbackRedirectUri, 302);
61
- return;
62
- }
63
- event.context.logtoClient = logto;
64
- event.context.logtoUser = await logto.isAuthenticated() ? await trySafe(async () => fetchUserInfo ? logto.fetchUserInfo() : logto.getIdTokenClaims()) : void 0;
6
+ await logtoEventHandler(event, config);
65
7
  });
@@ -0,0 +1,3 @@
1
+ import { type H3Event } from 'h3';
2
+ import type { RuntimeConfig } from 'nuxt/schema';
3
+ export declare const logtoEventHandler: (event: H3Event, config: RuntimeConfig) => Promise<void>;
@@ -0,0 +1,63 @@
1
+ import LogtoClient, { CookieStorage } from "@logto/node";
2
+ import { trySafe } from "@silverhand/essentials";
3
+ import { getRequestURL, getCookie, setCookie, sendRedirect } from "h3";
4
+ import { defaults } from "./constants.js";
5
+ export const logtoEventHandler = async (event, config) => {
6
+ const logtoConfig = config.logto;
7
+ const {
8
+ cookieName,
9
+ cookieEncryptionKey,
10
+ cookieSecure,
11
+ fetchUserInfo,
12
+ pathnames,
13
+ postCallbackRedirectUri,
14
+ postLogoutRedirectUri,
15
+ customRedirectBaseUrl,
16
+ signInOptions,
17
+ ...clientConfig
18
+ } = logtoConfig;
19
+ const defaultValueKeys = Object.entries(defaults).filter(([key, value]) => logtoConfig[key] === value).map(([key]) => key);
20
+ if (defaultValueKeys.length > 0) {
21
+ console.warn(
22
+ `The following Logto configuration keys have default values: ${defaultValueKeys.join(
23
+ ", "
24
+ )}. Please replace them with your own values.`
25
+ );
26
+ }
27
+ const requestUrl = getRequestURL(event);
28
+ const url = customRedirectBaseUrl ? new URL(requestUrl.pathname + requestUrl.search + requestUrl.hash, customRedirectBaseUrl) : requestUrl;
29
+ const storage = new CookieStorage({
30
+ cookieKey: cookieName,
31
+ encryptionKey: cookieEncryptionKey,
32
+ isSecure: cookieSecure,
33
+ getCookie: async (name) => getCookie(event, name),
34
+ setCookie: async (name, value, options) => {
35
+ setCookie(event, name, value, options);
36
+ }
37
+ });
38
+ await storage.init();
39
+ const logto = new LogtoClient(clientConfig, {
40
+ navigate: async (url2) => {
41
+ await sendRedirect(event, url2, 302);
42
+ },
43
+ storage
44
+ });
45
+ if (url.pathname === pathnames.signIn) {
46
+ await logto.signIn({
47
+ ...signInOptions,
48
+ redirectUri: new URL(pathnames.callback, url).href
49
+ });
50
+ return;
51
+ }
52
+ if (url.pathname === pathnames.signOut) {
53
+ await logto.signOut(new URL(postLogoutRedirectUri, url).href);
54
+ return;
55
+ }
56
+ if (url.pathname === pathnames.callback) {
57
+ await logto.handleSignInCallback(url.href);
58
+ await sendRedirect(event, postCallbackRedirectUri, 302);
59
+ return;
60
+ }
61
+ event.context.logtoClient = logto;
62
+ event.context.logtoUser = await logto.isAuthenticated() ? await trySafe(async () => fetchUserInfo ? logto.fetchUserInfo() : logto.getIdTokenClaims()) : void 0;
63
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/nuxt",
3
- "version": "1.1.5",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -19,20 +19,20 @@
19
19
  "directory": "packages/nuxt"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuxt/module-builder": "^0.8.0",
23
- "@nuxt/test-utils": "^3.12.1",
22
+ "@nuxt/module-builder": "^0.8.4",
23
+ "@nuxt/test-utils": "^3.15.1",
24
24
  "@silverhand/eslint-config": "^6.0.1",
25
- "@vitest/coverage-v8": "^1.6.0",
25
+ "@vitest/coverage-v8": "^2.1.9",
26
26
  "@vue/test-utils": "^2.4.4",
27
27
  "eslint": "^8.57.0",
28
- "h3": "^1.11.1",
29
- "happy-dom": "^15.10.2",
28
+ "h3": "^1.13.0",
29
+ "happy-dom": "^16.0.0",
30
30
  "lint-staged": "^15.0.0",
31
- "nuxt": "^3.12.4",
31
+ "nuxt": "^3.15.4",
32
32
  "prettier": "^3.0.0",
33
33
  "typescript": "^5.3.3",
34
- "vitest": "^1.6.0",
35
- "vue": "^3.4.19"
34
+ "vitest": "^2.1.9",
35
+ "vue": "^3.5.13"
36
36
  },
37
37
  "eslintConfig": {
38
38
  "extends": "@silverhand"
@@ -42,10 +42,10 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@nuxt/kit": "^3.10.2",
45
+ "@nuxt/kit": "^3.15.0",
46
46
  "@silverhand/essentials": "^2.9.2",
47
47
  "defu": "^6.1.4",
48
- "@logto/node": "^3.1.0"
48
+ "@logto/node": "^3.1.1"
49
49
  },
50
50
  "scripts": {
51
51
  "precommit": "lint-staged",