@logto/nuxt 0.0.0 → 0.1.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/README.md +9 -0
- package/dist/module.d.mts +56 -5
- package/dist/module.d.ts +56 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -1
- package/dist/runtime/composables/use-logto-client.d.ts +19 -1
- package/dist/runtime/composables/use-logto-client.mjs +1 -2
- package/dist/runtime/composables/use-logto-user.d.ts +18 -0
- package/dist/runtime/server/event-handler.d.ts +1 -1
- package/dist/runtime/server/event-handler.mjs +1 -0
- package/dist/runtime/utils/constants.d.ts +3 -0
- package/dist/runtime/utils/types.d.ts +43 -5
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -37,6 +37,15 @@ Check out the full JS repo and try it with pnpm.
|
|
|
37
37
|
pnpm i && pnpm dev
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
The minimal configuration to run the playground is (use `.env` file for example):
|
|
41
|
+
|
|
42
|
+
```env
|
|
43
|
+
NUXT_LOGTO_ENDPOINT=<your-logto-endpoint>
|
|
44
|
+
NUXT_LOGTO_APP_ID=<your-logto-app-id>
|
|
45
|
+
NUXT_LOGTO_APP_SECRET=<your-logto-app-secret>
|
|
46
|
+
NUXT_LOGTO_COOKIE_ENCRYPTION_KEY=<random-string>
|
|
47
|
+
```
|
|
48
|
+
|
|
40
49
|
## Resources
|
|
41
50
|
|
|
42
51
|
[](https://logto.io/)
|
package/dist/module.d.mts
CHANGED
|
@@ -15,24 +15,75 @@ type LogtoModuleOptions = {
|
|
|
15
15
|
cookieName?: string;
|
|
16
16
|
/**
|
|
17
17
|
* If Logto should fetch from the [userinfo endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
18
|
-
*
|
|
18
|
+
* in the server side for the `event.context.logtoUser` property (used by `useLogtoUser` composable).
|
|
19
|
+
*
|
|
20
|
+
* This is useful when you need to fetch additional claims like `custom_data`.
|
|
19
21
|
*/
|
|
20
22
|
fetchUserInfo: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The URI to redirect to after a successful sign-in callback.
|
|
25
|
+
*
|
|
26
|
+
* This is NOT the redirect URI used in Logto's configuration. This is the URI that the user will be
|
|
27
|
+
* redirected to after the sign-in callback is handled by the server.
|
|
28
|
+
*
|
|
29
|
+
* @default '/'
|
|
30
|
+
*/
|
|
21
31
|
postCallbackRedirectUri: string;
|
|
32
|
+
/**
|
|
33
|
+
* The URI to redirect to after a successful sign-out.
|
|
34
|
+
*
|
|
35
|
+
* This is the post sign-out redirect URI used in Logto's configuration.
|
|
36
|
+
*
|
|
37
|
+
* @default '/'
|
|
38
|
+
*/
|
|
22
39
|
postLogoutRedirectUri: string;
|
|
40
|
+
/**
|
|
41
|
+
* Pathnames for the sign-in, sign-out, and callback URIs. They will be handled by the Logto
|
|
42
|
+
* event handler.
|
|
43
|
+
*/
|
|
23
44
|
pathnames: {
|
|
45
|
+
/**
|
|
46
|
+
* The URI for initiating the sign-in process.
|
|
47
|
+
*
|
|
48
|
+
* @default '/sign-in'
|
|
49
|
+
*/
|
|
24
50
|
signIn: string;
|
|
51
|
+
/**
|
|
52
|
+
* The URI for initiating the sign-out process.
|
|
53
|
+
*
|
|
54
|
+
* @default '/sign-out'
|
|
55
|
+
*/
|
|
25
56
|
signOut: string;
|
|
57
|
+
/**
|
|
58
|
+
* The URI for handling the sign-in callback.
|
|
59
|
+
*
|
|
60
|
+
* @default '/callback'
|
|
61
|
+
*/
|
|
26
62
|
callback: string;
|
|
27
63
|
};
|
|
28
64
|
};
|
|
65
|
+
/** The full runtime configuration for the Logto module. */
|
|
29
66
|
type LogtoRuntimeConfig = LogtoModuleOptions & {
|
|
67
|
+
/**
|
|
68
|
+
* The secret used to encrypt the Logto cookie. It should be a random string.
|
|
69
|
+
*/
|
|
30
70
|
cookieEncryptionKey: string;
|
|
31
|
-
} & Omit<LogtoConfig, 'appSecret'> &
|
|
32
|
-
appSecret: NonNullable<LogtoConfig['appSecret']>;
|
|
33
|
-
};
|
|
71
|
+
} & Omit<LogtoConfig, 'appSecret'> & Required<Pick<LogtoConfig, 'appSecret'>>;
|
|
34
72
|
type LogtoRuntimeConfigInput = DeepPartial<LogtoRuntimeConfig>;
|
|
35
73
|
|
|
74
|
+
/** The keys used to store the Logto state in `useState()`. */
|
|
75
|
+
declare enum LogtoStateKey {
|
|
76
|
+
/** The key used to store the Logto user information. */
|
|
77
|
+
User = "logto.user"
|
|
78
|
+
}
|
|
79
|
+
/** The default Logto runtime configuration values that should be replaced with your own values. */
|
|
80
|
+
declare const defaults: Readonly<{
|
|
81
|
+
readonly endpoint: "<replace-with-logto-endpoint>";
|
|
82
|
+
readonly appId: "<replace-with-logto-app-id>";
|
|
83
|
+
readonly appSecret: "<replace-with-logto-app-secret>";
|
|
84
|
+
readonly cookieEncryptionKey: "<replace-with-random-string>";
|
|
85
|
+
}>;
|
|
86
|
+
|
|
36
87
|
declare const logtoModule: NuxtModule<LogtoRuntimeConfigInput>;
|
|
37
88
|
|
|
38
|
-
export { logtoModule as default };
|
|
89
|
+
export { type LogtoRuntimeConfig, type LogtoRuntimeConfigInput, LogtoStateKey, logtoModule as default, defaults };
|
package/dist/module.d.ts
CHANGED
|
@@ -15,24 +15,75 @@ type LogtoModuleOptions = {
|
|
|
15
15
|
cookieName?: string;
|
|
16
16
|
/**
|
|
17
17
|
* If Logto should fetch from the [userinfo endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
18
|
-
*
|
|
18
|
+
* in the server side for the `event.context.logtoUser` property (used by `useLogtoUser` composable).
|
|
19
|
+
*
|
|
20
|
+
* This is useful when you need to fetch additional claims like `custom_data`.
|
|
19
21
|
*/
|
|
20
22
|
fetchUserInfo: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The URI to redirect to after a successful sign-in callback.
|
|
25
|
+
*
|
|
26
|
+
* This is NOT the redirect URI used in Logto's configuration. This is the URI that the user will be
|
|
27
|
+
* redirected to after the sign-in callback is handled by the server.
|
|
28
|
+
*
|
|
29
|
+
* @default '/'
|
|
30
|
+
*/
|
|
21
31
|
postCallbackRedirectUri: string;
|
|
32
|
+
/**
|
|
33
|
+
* The URI to redirect to after a successful sign-out.
|
|
34
|
+
*
|
|
35
|
+
* This is the post sign-out redirect URI used in Logto's configuration.
|
|
36
|
+
*
|
|
37
|
+
* @default '/'
|
|
38
|
+
*/
|
|
22
39
|
postLogoutRedirectUri: string;
|
|
40
|
+
/**
|
|
41
|
+
* Pathnames for the sign-in, sign-out, and callback URIs. They will be handled by the Logto
|
|
42
|
+
* event handler.
|
|
43
|
+
*/
|
|
23
44
|
pathnames: {
|
|
45
|
+
/**
|
|
46
|
+
* The URI for initiating the sign-in process.
|
|
47
|
+
*
|
|
48
|
+
* @default '/sign-in'
|
|
49
|
+
*/
|
|
24
50
|
signIn: string;
|
|
51
|
+
/**
|
|
52
|
+
* The URI for initiating the sign-out process.
|
|
53
|
+
*
|
|
54
|
+
* @default '/sign-out'
|
|
55
|
+
*/
|
|
25
56
|
signOut: string;
|
|
57
|
+
/**
|
|
58
|
+
* The URI for handling the sign-in callback.
|
|
59
|
+
*
|
|
60
|
+
* @default '/callback'
|
|
61
|
+
*/
|
|
26
62
|
callback: string;
|
|
27
63
|
};
|
|
28
64
|
};
|
|
65
|
+
/** The full runtime configuration for the Logto module. */
|
|
29
66
|
type LogtoRuntimeConfig = LogtoModuleOptions & {
|
|
67
|
+
/**
|
|
68
|
+
* The secret used to encrypt the Logto cookie. It should be a random string.
|
|
69
|
+
*/
|
|
30
70
|
cookieEncryptionKey: string;
|
|
31
|
-
} & Omit<LogtoConfig, 'appSecret'> &
|
|
32
|
-
appSecret: NonNullable<LogtoConfig['appSecret']>;
|
|
33
|
-
};
|
|
71
|
+
} & Omit<LogtoConfig, 'appSecret'> & Required<Pick<LogtoConfig, 'appSecret'>>;
|
|
34
72
|
type LogtoRuntimeConfigInput = DeepPartial<LogtoRuntimeConfig>;
|
|
35
73
|
|
|
74
|
+
/** The keys used to store the Logto state in `useState()`. */
|
|
75
|
+
declare enum LogtoStateKey {
|
|
76
|
+
/** The key used to store the Logto user information. */
|
|
77
|
+
User = "logto.user"
|
|
78
|
+
}
|
|
79
|
+
/** The default Logto runtime configuration values that should be replaced with your own values. */
|
|
80
|
+
declare const defaults: Readonly<{
|
|
81
|
+
readonly endpoint: "<replace-with-logto-endpoint>";
|
|
82
|
+
readonly appId: "<replace-with-logto-app-id>";
|
|
83
|
+
readonly appSecret: "<replace-with-logto-app-secret>";
|
|
84
|
+
readonly cookieEncryptionKey: "<replace-with-random-string>";
|
|
85
|
+
}>;
|
|
86
|
+
|
|
36
87
|
declare const logtoModule: NuxtModule<LogtoRuntimeConfigInput>;
|
|
37
88
|
|
|
38
|
-
export { logtoModule as default };
|
|
89
|
+
export { type LogtoRuntimeConfig, type LogtoRuntimeConfigInput, LogtoStateKey, logtoModule as default, defaults };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,6 +3,10 @@ import { defu } from 'defu';
|
|
|
3
3
|
export * from '@logto/node';
|
|
4
4
|
export { default as LogtoNodeClient } from '@logto/node';
|
|
5
5
|
|
|
6
|
+
var LogtoStateKey = /* @__PURE__ */ ((LogtoStateKey2) => {
|
|
7
|
+
LogtoStateKey2["User"] = "logto.user";
|
|
8
|
+
return LogtoStateKey2;
|
|
9
|
+
})(LogtoStateKey || {});
|
|
6
10
|
const defaults = Object.freeze({
|
|
7
11
|
endpoint: "<replace-with-logto-endpoint>",
|
|
8
12
|
appId: "<replace-with-logto-app-id>",
|
|
@@ -40,4 +44,4 @@ const logtoModule = defineNuxtModule({
|
|
|
40
44
|
}
|
|
41
45
|
});
|
|
42
46
|
|
|
43
|
-
export { logtoModule as default };
|
|
47
|
+
export { LogtoStateKey, logtoModule as default, defaults };
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import LogtoClient from '@logto/node';
|
|
1
|
+
import type LogtoClient from '@logto/node';
|
|
2
|
+
/**
|
|
3
|
+
* Get the Logto client instance in the current context. Returns `undefined` if the client is not
|
|
4
|
+
* available.
|
|
5
|
+
*
|
|
6
|
+
* Note: This composable only works in the server side and relies on the SSR context which is
|
|
7
|
+
* filled by the Logto event handler.
|
|
8
|
+
*
|
|
9
|
+
* @returns The Logto client instance if available, otherwise `undefined`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const client = useLogtoClient();
|
|
14
|
+
*
|
|
15
|
+
* if (client) {
|
|
16
|
+
* const token = await client.getAccessToken();
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
2
20
|
export default function useLogtoClient(): LogtoClient | undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import LogtoClient from "@logto/node";
|
|
2
1
|
import { useNuxtApp } from "#app";
|
|
3
2
|
export default function useLogtoClient() {
|
|
4
3
|
const nuxtApp = useNuxtApp();
|
|
5
4
|
const client = nuxtApp.ssrContext?.event.context.logtoClient;
|
|
6
|
-
return client
|
|
5
|
+
return client;
|
|
7
6
|
}
|
|
@@ -1 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the Logto user information. If the user is not signed in, this composable will return
|
|
3
|
+
* `undefined`.
|
|
4
|
+
*
|
|
5
|
+
* Note: This composable relies on the SSR context which is filled by the Logto event handler. Once
|
|
6
|
+
* the user is signed in, the user information will be available in both the server and client side.
|
|
7
|
+
*
|
|
8
|
+
* @returns The user information if the user is signed in, otherwise `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const user = useLogtoUser();
|
|
13
|
+
*
|
|
14
|
+
* if (user) {
|
|
15
|
+
* console.log('User is signed in:', user); // { sub: '123', ... }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export default function useLogtoUser(): any;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/** The keys used to store the Logto state in `useState()`. */
|
|
1
2
|
export declare enum LogtoStateKey {
|
|
3
|
+
/** The key used to store the Logto user information. */
|
|
2
4
|
User = "logto.user"
|
|
3
5
|
}
|
|
6
|
+
/** The default Logto runtime configuration values that should be replaced with your own values. */
|
|
4
7
|
export declare const defaults: Readonly<{
|
|
5
8
|
readonly endpoint: "<replace-with-logto-endpoint>";
|
|
6
9
|
readonly appId: "<replace-with-logto-app-id>";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LogtoConfig } from '@logto/node';
|
|
2
|
-
|
|
2
|
+
type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
3
3
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
4
4
|
} : T;
|
|
5
5
|
type LogtoModuleOptions = {
|
|
@@ -11,21 +11,59 @@ type LogtoModuleOptions = {
|
|
|
11
11
|
cookieName?: string;
|
|
12
12
|
/**
|
|
13
13
|
* If Logto should fetch from the [userinfo endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
14
|
-
*
|
|
14
|
+
* in the server side for the `event.context.logtoUser` property (used by `useLogtoUser` composable).
|
|
15
|
+
*
|
|
16
|
+
* This is useful when you need to fetch additional claims like `custom_data`.
|
|
15
17
|
*/
|
|
16
18
|
fetchUserInfo: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The URI to redirect to after a successful sign-in callback.
|
|
21
|
+
*
|
|
22
|
+
* This is NOT the redirect URI used in Logto's configuration. This is the URI that the user will be
|
|
23
|
+
* redirected to after the sign-in callback is handled by the server.
|
|
24
|
+
*
|
|
25
|
+
* @default '/'
|
|
26
|
+
*/
|
|
17
27
|
postCallbackRedirectUri: string;
|
|
28
|
+
/**
|
|
29
|
+
* The URI to redirect to after a successful sign-out.
|
|
30
|
+
*
|
|
31
|
+
* This is the post sign-out redirect URI used in Logto's configuration.
|
|
32
|
+
*
|
|
33
|
+
* @default '/'
|
|
34
|
+
*/
|
|
18
35
|
postLogoutRedirectUri: string;
|
|
36
|
+
/**
|
|
37
|
+
* Pathnames for the sign-in, sign-out, and callback URIs. They will be handled by the Logto
|
|
38
|
+
* event handler.
|
|
39
|
+
*/
|
|
19
40
|
pathnames: {
|
|
41
|
+
/**
|
|
42
|
+
* The URI for initiating the sign-in process.
|
|
43
|
+
*
|
|
44
|
+
* @default '/sign-in'
|
|
45
|
+
*/
|
|
20
46
|
signIn: string;
|
|
47
|
+
/**
|
|
48
|
+
* The URI for initiating the sign-out process.
|
|
49
|
+
*
|
|
50
|
+
* @default '/sign-out'
|
|
51
|
+
*/
|
|
21
52
|
signOut: string;
|
|
53
|
+
/**
|
|
54
|
+
* The URI for handling the sign-in callback.
|
|
55
|
+
*
|
|
56
|
+
* @default '/callback'
|
|
57
|
+
*/
|
|
22
58
|
callback: string;
|
|
23
59
|
};
|
|
24
60
|
};
|
|
61
|
+
/** The full runtime configuration for the Logto module. */
|
|
25
62
|
export type LogtoRuntimeConfig = LogtoModuleOptions & {
|
|
63
|
+
/**
|
|
64
|
+
* The secret used to encrypt the Logto cookie. It should be a random string.
|
|
65
|
+
*/
|
|
26
66
|
cookieEncryptionKey: string;
|
|
27
|
-
} & Omit<LogtoConfig, 'appSecret'> &
|
|
28
|
-
appSecret: NonNullable<LogtoConfig['appSecret']>;
|
|
29
|
-
};
|
|
67
|
+
} & Omit<LogtoConfig, 'appSecret'> & Required<Pick<LogtoConfig, 'appSecret'>>;
|
|
30
68
|
export type LogtoRuntimeConfigInput = DeepPartial<LogtoRuntimeConfig>;
|
|
31
69
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,13 +22,17 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@nuxt/module-builder": "^0.5.5",
|
|
25
|
+
"@nuxt/test-utils": "^3.11.0",
|
|
25
26
|
"@silverhand/eslint-config": "^5.0.0",
|
|
27
|
+
"@vue/test-utils": "^2.4.4",
|
|
26
28
|
"eslint": "^8.56.0",
|
|
27
29
|
"h3": "^1.10.2",
|
|
30
|
+
"happy-dom": "^13.4.1",
|
|
28
31
|
"lint-staged": "^15.0.0",
|
|
29
32
|
"nuxt": "^3.10.2",
|
|
30
33
|
"prettier": "^3.0.0",
|
|
31
34
|
"typescript": "^5.3.3",
|
|
35
|
+
"vitest": "^1.3.1",
|
|
32
36
|
"vue": "^3.4.19"
|
|
33
37
|
},
|
|
34
38
|
"eslintConfig": {
|
|
@@ -48,6 +52,7 @@
|
|
|
48
52
|
"dev": "nuxi dev playground",
|
|
49
53
|
"dev:prepare": "nuxt-module-build prepare && nuxi prepare playground",
|
|
50
54
|
"build": "nuxt-module-build prepare && nuxt-module-build build",
|
|
55
|
+
"test": "vitest",
|
|
51
56
|
"check": "tsc --noEmit",
|
|
52
57
|
"lint": "eslint --ext .ts src"
|
|
53
58
|
}
|