@logto/next 3.4.0 → 3.6.0
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/lib/server-actions/index.cjs +22 -0
- package/lib/server-actions/index.d.ts +18 -4
- package/lib/server-actions/index.js +21 -1
- package/lib/src/index.cjs +8 -0
- package/lib/src/index.d.ts +3 -1
- package/lib/src/index.js +8 -0
- package/package.json +2 -2
|
@@ -85,11 +85,33 @@ const getAccessToken = async (config, resource, organizationId) => {
|
|
|
85
85
|
const getOrganizationToken = async (config, organizationId) => {
|
|
86
86
|
return getAccessToken(config, undefined, organizationId);
|
|
87
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Get access token for the specified resource or organization,
|
|
90
|
+
* this function can be used in React Server Components (RSC)
|
|
91
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
92
|
+
* When using server actions or API routes, we highly recommand to use the getAccessToken method
|
|
93
|
+
*/
|
|
94
|
+
const getAccessTokenRSC = async (config, resource, organizationId) => {
|
|
95
|
+
const client$1 = new client.default(config);
|
|
96
|
+
const { nodeClient } = await client$1.createNodeClientFromHeaders(await cookie.getCookies(config));
|
|
97
|
+
return nodeClient.getAccessToken(resource, organizationId);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Get organization token from session,
|
|
101
|
+
* this function can be used in React Server Components (RSC)
|
|
102
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
103
|
+
* When using server actions or API routes, we highly recommand to use the getOrganizationToken method
|
|
104
|
+
*/
|
|
105
|
+
const getOrganizationTokenRSC = async (config, organizationId) => {
|
|
106
|
+
return getAccessTokenRSC(config, undefined, organizationId);
|
|
107
|
+
};
|
|
88
108
|
|
|
89
109
|
exports.default = client.default;
|
|
90
110
|
exports.getAccessToken = getAccessToken;
|
|
111
|
+
exports.getAccessTokenRSC = getAccessTokenRSC;
|
|
91
112
|
exports.getLogtoContext = getLogtoContext;
|
|
92
113
|
exports.getOrganizationToken = getOrganizationToken;
|
|
114
|
+
exports.getOrganizationTokenRSC = getOrganizationTokenRSC;
|
|
93
115
|
exports.getOrganizationTokens = getOrganizationTokens;
|
|
94
116
|
exports.handleSignIn = handleSignIn;
|
|
95
117
|
exports.signIn = signIn;
|
|
@@ -15,13 +15,13 @@ export declare const signOut: (config: LogtoNextConfig, redirectUri?: string) =>
|
|
|
15
15
|
* Get Logto context from session, including auth status and claims
|
|
16
16
|
*/
|
|
17
17
|
export declare const getLogtoContext: (config: LogtoNextConfig, getContextParameters?: Omit<GetContextParameters, 'getAccessToken' | 'resource' | 'organizationId' | 'getOrganizationToken'> & {
|
|
18
|
-
/** @deprecated use
|
|
18
|
+
/** @deprecated use getAccessTokenRSC() */
|
|
19
19
|
getAccessToken?: GetContextParameters['getAccessToken'];
|
|
20
|
-
/** @deprecated use
|
|
20
|
+
/** @deprecated use getOrganizationTokenRSC() */
|
|
21
21
|
getOrganizationToken?: GetContextParameters['getOrganizationToken'];
|
|
22
|
-
/** @deprecated use
|
|
22
|
+
/** @deprecated use getAccessTokenRSC() */
|
|
23
23
|
resource?: GetContextParameters['resource'];
|
|
24
|
-
/** @deprecated use
|
|
24
|
+
/** @deprecated use getOrganizationTokenRSC() */
|
|
25
25
|
organizationId?: GetContextParameters['organizationId'];
|
|
26
26
|
}) => Promise<LogtoContext>;
|
|
27
27
|
/**
|
|
@@ -43,4 +43,18 @@ export declare const getAccessToken: (config: LogtoNextConfig, resource?: string
|
|
|
43
43
|
* this function can be used in server actions or API routes
|
|
44
44
|
*/
|
|
45
45
|
export declare const getOrganizationToken: (config: LogtoNextConfig, organizationId?: string) => Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Get access token for the specified resource or organization,
|
|
48
|
+
* this function can be used in React Server Components (RSC)
|
|
49
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
50
|
+
* When using server actions or API routes, we highly recommand to use the getAccessToken method
|
|
51
|
+
*/
|
|
52
|
+
export declare const getAccessTokenRSC: (config: LogtoNextConfig, resource?: string, organizationId?: string) => Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Get organization token from session,
|
|
55
|
+
* this function can be used in React Server Components (RSC)
|
|
56
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
57
|
+
* When using server actions or API routes, we highly recommand to use the getOrganizationToken method
|
|
58
|
+
*/
|
|
59
|
+
export declare const getOrganizationTokenRSC: (config: LogtoNextConfig, organizationId?: string) => Promise<string>;
|
|
46
60
|
export { default } from './client';
|
|
@@ -81,5 +81,25 @@ const getAccessToken = async (config, resource, organizationId) => {
|
|
|
81
81
|
const getOrganizationToken = async (config, organizationId) => {
|
|
82
82
|
return getAccessToken(config, undefined, organizationId);
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* Get access token for the specified resource or organization,
|
|
86
|
+
* this function can be used in React Server Components (RSC)
|
|
87
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
88
|
+
* When using server actions or API routes, we highly recommand to use the getAccessToken method
|
|
89
|
+
*/
|
|
90
|
+
const getAccessTokenRSC = async (config, resource, organizationId) => {
|
|
91
|
+
const client = new LogtoClient(config);
|
|
92
|
+
const { nodeClient } = await client.createNodeClientFromHeaders(await getCookies(config));
|
|
93
|
+
return nodeClient.getAccessToken(resource, organizationId);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Get organization token from session,
|
|
97
|
+
* this function can be used in React Server Components (RSC)
|
|
98
|
+
* Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
|
|
99
|
+
* When using server actions or API routes, we highly recommand to use the getOrganizationToken method
|
|
100
|
+
*/
|
|
101
|
+
const getOrganizationTokenRSC = async (config, organizationId) => {
|
|
102
|
+
return getAccessTokenRSC(config, undefined, organizationId);
|
|
103
|
+
};
|
|
84
104
|
|
|
85
|
-
export { LogtoClient as default, getAccessToken, getLogtoContext, getOrganizationToken, getOrganizationTokens, handleSignIn, signIn, signOut };
|
|
105
|
+
export { LogtoClient as default, getAccessToken, getAccessTokenRSC, getLogtoContext, getOrganizationToken, getOrganizationTokenRSC, getOrganizationTokens, handleSignIn, signIn, signOut };
|
package/lib/src/index.cjs
CHANGED
|
@@ -62,6 +62,14 @@ class LogtoClient extends client.default {
|
|
|
62
62
|
}
|
|
63
63
|
response.status(404).end();
|
|
64
64
|
};
|
|
65
|
+
this.getAccessToken = async (request, response, resource) => {
|
|
66
|
+
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
67
|
+
return nodeClient.getAccessToken(resource);
|
|
68
|
+
};
|
|
69
|
+
this.getOrganizationToken = async (request, response, organizationId) => {
|
|
70
|
+
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
71
|
+
return nodeClient.getOrganizationToken(organizationId);
|
|
72
|
+
};
|
|
65
73
|
this.withLogtoApiRoute = (handler, config = {}, onError) => utils.buildHandler(async (request, response) => {
|
|
66
74
|
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
67
75
|
const user = await nodeClient.getContext(config);
|
package/lib/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { type IncomingMessage, type ServerResponse } from 'node:http';
|
|
3
3
|
import NodeClient, { type GetContextParameters, type InteractionMode } from '@logto/node';
|
|
4
|
-
import { type GetServerSidePropsResult, type GetServerSidePropsContext, type NextApiHandler } from 'next';
|
|
4
|
+
import { type GetServerSidePropsResult, type GetServerSidePropsContext, type NextApiHandler, type NextApiRequest, type NextApiResponse } from 'next';
|
|
5
5
|
import { type NextApiRequestCookies } from 'next/dist/server/api-utils/index.js';
|
|
6
6
|
import LogtoNextBaseClient from './client.js';
|
|
7
7
|
import type { ErrorHandler, LogtoNextConfig } from './types.js';
|
|
@@ -15,6 +15,8 @@ export default class LogtoClient extends LogtoNextBaseClient {
|
|
|
15
15
|
handleSignOut: (redirectUri?: string, onError?: ErrorHandler) => NextApiHandler;
|
|
16
16
|
handleUser: (configs?: GetContextParameters, onError?: ErrorHandler) => NextApiHandler;
|
|
17
17
|
handleAuthRoutes: (configs?: GetContextParameters, onError?: ErrorHandler) => NextApiHandler;
|
|
18
|
+
getAccessToken: (request: NextApiRequest, response: NextApiResponse, resource: string) => Promise<string>;
|
|
19
|
+
getOrganizationToken: (request: NextApiRequest, response: NextApiResponse, organizationId: string) => Promise<string>;
|
|
18
20
|
withLogtoApiRoute: (handler: NextApiHandler, config?: GetContextParameters, onError?: ErrorHandler) => NextApiHandler;
|
|
19
21
|
withLogtoSsr: <P extends Record<string, unknown> = Record<string, unknown>>(handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>, configs?: GetContextParameters, onError?: ((error: unknown) => unknown) | undefined) => (context: GetServerSidePropsContext) => Promise<NextApiHandler>;
|
|
20
22
|
createNodeClientFromNextApi(request: IncomingMessage & {
|
package/lib/src/index.js
CHANGED
|
@@ -55,6 +55,14 @@ class LogtoClient extends LogtoNextBaseClient {
|
|
|
55
55
|
}
|
|
56
56
|
response.status(404).end();
|
|
57
57
|
};
|
|
58
|
+
this.getAccessToken = async (request, response, resource) => {
|
|
59
|
+
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
60
|
+
return nodeClient.getAccessToken(resource);
|
|
61
|
+
};
|
|
62
|
+
this.getOrganizationToken = async (request, response, organizationId) => {
|
|
63
|
+
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
64
|
+
return nodeClient.getOrganizationToken(organizationId);
|
|
65
|
+
};
|
|
58
66
|
this.withLogtoApiRoute = (handler, config = {}, onError) => buildHandler(async (request, response) => {
|
|
59
67
|
const nodeClient = await this.createNodeClientFromNextApi(request, response);
|
|
60
68
|
const user = await nodeClient.getContext(config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/next",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/src/index.cjs",
|
|
6
6
|
"module": "./lib/src/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@edge-runtime/cookies": "^4.0.0",
|
|
49
|
-
"@logto/node": "^2.5.
|
|
49
|
+
"@logto/node": "^2.5.6"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@silverhand/eslint-config": "^6.0.1",
|