@logto/next 4.1.0 → 4.2.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/edge/index.js CHANGED
@@ -79,7 +79,8 @@ class LogtoClient extends LogtoNextBaseClient {
79
79
  const headers = new Headers();
80
80
  const responseCookies = new ResponseCookies(headers);
81
81
  this.storage = new CookieStorage({
82
- encryptionKey: this.config.cookieSecret,
82
+ encryptionKey: this.config.cookieSecret ?? '',
83
+ sessionWrapper: this.config.sessionWrapper,
83
84
  cookieKey: `logto_${this.config.appId}`,
84
85
  isSecure: this.config.cookieSecure,
85
86
  getCookie: (name) => {
@@ -61,7 +61,8 @@ class LogtoClient extends LogtoNextBaseClient {
61
61
  async createNodeClient({ ignoreCookieChange } = {}) {
62
62
  const { cookies } = await import('next/headers');
63
63
  this.storage = new CookieStorage({
64
- encryptionKey: this.config.cookieSecret,
64
+ encryptionKey: this.config.cookieSecret ?? '',
65
+ sessionWrapper: this.config.sessionWrapper,
65
66
  cookieKey: `logto_${this.config.appId}`,
66
67
  isSecure: this.config.cookieSecure,
67
68
  getCookie: async (...args) => {
@@ -11,6 +11,8 @@ async function signIn(config, options, interactionMode) {
11
11
  }
12
12
  /**
13
13
  * Handle sign in callback from search params or full redirect URL, save tokens to session
14
+ * @param config The Logto configuration object
15
+ * @param searchParamsOrUrl Either URLSearchParams from the callback URL or the complete URL object
14
16
  */
15
17
  async function handleSignIn(config, searchParamsOrUrl) {
16
18
  const client = new LogtoClient(config);
@@ -7,7 +7,7 @@ import LogtoNextBaseClient from './client.js';
7
7
  import type { ErrorHandler, LogtoNextConfig } from './types.js';
8
8
  export type { LogtoNextConfig } from './types.js';
9
9
  export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, } from '@logto/node';
10
- export type { AccessTokenClaims, IdTokenClaims, LogtoContext, InteractionMode, LogtoErrorCode, UserInfoResponse, } from '@logto/node';
10
+ export type { AccessTokenClaims, IdTokenClaims, LogtoContext, InteractionMode, LogtoErrorCode, UserInfoResponse, SessionWrapper, SessionData, } from '@logto/node';
11
11
  export default class LogtoClient extends LogtoNextBaseClient {
12
12
  constructor(config: LogtoNextConfig);
13
13
  handleSignIn: (options?: (SignInOptions & {
package/lib/src/index.js CHANGED
@@ -84,10 +84,15 @@ class LogtoClient extends LogtoNextBaseClient {
84
84
  response.redirect(this.navigateUrl);
85
85
  }
86
86
  }, options.onError);
87
+ if (!config.sessionWrapper && !config.cookieSecret) {
88
+ throw new Error('cookieSecret is required when using default session wrapper');
89
+ }
87
90
  }
88
91
  async createNodeClientFromNextApi(request, response) {
89
92
  this.storage = new CookieStorage({
90
- encryptionKey: this.config.cookieSecret,
93
+ // The type checking is done in the constructor, encryptionKey is required when using default session wrapper
94
+ encryptionKey: this.config.cookieSecret ?? '',
95
+ sessionWrapper: this.config.sessionWrapper,
91
96
  cookieKey: `logto_${this.config.appId}`,
92
97
  isSecure: this.config.cookieSecure,
93
98
  getCookie: (name) => {
@@ -1,10 +1,17 @@
1
- import type { LogtoConfig } from '@logto/node';
1
+ import type { LogtoConfig, SessionWrapper } from '@logto/node';
2
2
  import type NodeClient from '@logto/node';
3
3
  import { type NextApiRequest, type NextApiResponse } from 'next';
4
4
  export type LogtoNextConfig = LogtoConfig & {
5
- cookieSecret: string;
6
5
  cookieSecure: boolean;
7
6
  baseUrl: string;
7
+ /**
8
+ * Can be provided to use custom session wrapper,
9
+ * for example, to use external storage solutions,
10
+ * you can save the session data in external storage and return a key in the sessionWrapper.wrap method,
11
+ * then use the key to get the session data from external storage in the sessionWrapper.unwrap method.
12
+ */
13
+ sessionWrapper?: SessionWrapper;
14
+ cookieSecret?: string;
8
15
  };
9
16
  export type Adapters = {
10
17
  NodeClient: typeof NodeClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/next",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "type": "module",
5
5
  "module": "./lib/src/index.js",
6
6
  "types": "./lib/src/index.d.ts",
@@ -43,23 +43,23 @@
43
43
  "dependencies": {
44
44
  "@edge-runtime/cookies": "^5.0.0",
45
45
  "cookie": "^1.0.0",
46
- "@logto/node": "^3.1.0"
46
+ "@logto/node": "^3.1.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@silverhand/eslint-config": "^6.0.1",
50
50
  "@silverhand/ts-config": "^6.0.0",
51
51
  "@silverhand/ts-config-react": "^6.0.0",
52
52
  "@types/cookie": "^0.6.0",
53
- "@vitest/coverage-v8": "^1.6.0",
53
+ "@vitest/coverage-v8": "^2.1.9",
54
54
  "eslint": "^8.57.0",
55
55
  "lint-staged": "^15.0.0",
56
- "next": "^15.0.4",
56
+ "next": "^15.1.2",
57
57
  "next-test-api-route-handler": "^4.0.14",
58
58
  "prettier": "^3.0.0",
59
59
  "react": "19.0.0",
60
60
  "react-dom": "19.0.0",
61
61
  "typescript": "^5.3.3",
62
- "vitest": "^1.6.0"
62
+ "vitest": "^2.1.9"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "next": ">=12"