@logto/remix 2.2.6 → 3.0.3

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.
Files changed (31) hide show
  1. package/README.md +29 -35
  2. package/package.json +3 -5
  3. package/lib/framework/get-cookie-header-from-request.cjs +0 -5
  4. package/lib/index.cjs +0 -69
  5. package/lib/infrastructure/logto/create-client.cjs +0 -17
  6. package/lib/infrastructure/logto/create-storage.cjs +0 -30
  7. package/lib/infrastructure/logto/get-context.cjs +0 -12
  8. package/lib/infrastructure/logto/handle-sign-in-callback.cjs +0 -12
  9. package/lib/infrastructure/logto/handle-sign-in.cjs +0 -30
  10. package/lib/infrastructure/logto/handle-sign-out.cjs +0 -26
  11. package/lib/infrastructure/logto/handle-sign-up.cjs +0 -30
  12. package/lib/infrastructure/logto/index.cjs +0 -23
  13. package/lib/useCases/getContext/GetContextController.cjs +0 -21
  14. package/lib/useCases/getContext/GetContextUseCase.cjs +0 -13
  15. package/lib/useCases/getContext/index.cjs +0 -19
  16. package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.cjs +0 -21
  17. package/lib/useCases/handleAuthRoutes/index.cjs +0 -48
  18. package/lib/useCases/handleSignIn/HandleSignInController.cjs +0 -31
  19. package/lib/useCases/handleSignIn/HandleSignInUseCase.cjs +0 -17
  20. package/lib/useCases/handleSignIn/index.cjs +0 -19
  21. package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.cjs +0 -42
  22. package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.cjs +0 -17
  23. package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.cjs +0 -16
  24. package/lib/useCases/handleSignInCallback/index.cjs +0 -19
  25. package/lib/useCases/handleSignOut/HandleSignOutController.cjs +0 -34
  26. package/lib/useCases/handleSignOut/HandleSignOutError.cjs +0 -17
  27. package/lib/useCases/handleSignOut/HandleSignOutUseCase.cjs +0 -17
  28. package/lib/useCases/handleSignOut/index.cjs +0 -19
  29. package/lib/useCases/handleSignUp/HandleSignUpController.cjs +0 -31
  30. package/lib/useCases/handleSignUp/HandleSignUpUseCase.cjs +0 -17
  31. package/lib/useCases/handleSignUp/index.cjs +0 -19
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Logto Remix SDK
2
+
2
3
  [![Version](https://img.shields.io/npm/v/@logto/remix)](https://www.npmjs.com/package/@logto/remix)
3
4
  [![Build Status](https://github.com/logto-io/js/actions/workflows/main.yml/badge.svg)](https://github.com/logto-io/js/actions/workflows/main.yml)
4
5
  [![Codecov](https://img.shields.io/codecov/c/github/logto-io/js)](https://app.codecov.io/gh/logto-io/js?branch=master)
@@ -7,6 +8,8 @@ The Logto Remix SDK written in TypeScript.
7
8
 
8
9
  ## Installation
9
10
 
11
+ **Note:** This package requires Node.js version 20 or higher.
12
+
10
13
  ### Using npm
11
14
 
12
15
  ```bash
@@ -30,24 +33,17 @@ pnpm add @logto/remix
30
33
  Before initializing the SDK, we have to create a `SessionStorage` instance which takes care of the session persistence. In our case, we want to use a cookie-based session:
31
34
 
32
35
  ```ts
33
- // services/authentication.ts
34
- import { createCookieSessionStorage } from "@remix-run/node";
36
+ // service/auth.server.ts
37
+ import { createCookieSessionStorage } from '@remix-run/node';
38
+ import { makeLogtoRemix } from '@logto/remix';
35
39
 
36
40
  const sessionStorage = createCookieSessionStorage({
37
41
  cookie: {
38
- name: "logto-session",
42
+ name: 'logto-session',
39
43
  maxAge: 14 * 24 * 60 * 60,
40
- secrets: ["s3cret1"],
44
+ secrets: ['secr3tSession'],
41
45
  },
42
46
  });
43
- ```
44
-
45
- Afterwards, we can initialize the SDK via:
46
-
47
- ```ts
48
- // app/services/authentication.ts
49
-
50
- import { makeLogtoRemix } from "@logto/remix";
51
47
 
52
48
  export const logto = makeLogtoRemix(
53
49
  {
@@ -64,29 +60,29 @@ Whereas the environment variables reflect the respective configuration of the ap
64
60
 
65
61
  ### Mounting the authentication route handlers
66
62
 
67
- The SDK ships with a convenient function that mounts the authentication routes: sign-in, sign-in callback and the sign-out route:
63
+ The SDK ships with a convenient function that mounts the authentication routes: sign-in, sign-in callback and the sign-out route. Create a file `routes/api.logto.$action.ts`
68
64
 
69
65
  ```ts
70
- // app/routes/api/logto/$action.ts
66
+ // routes/api.logto.$action.ts
71
67
 
72
- import { logto } from "../../../services/authentication";
68
+ import { logto } from '../../service/auth.server';
73
69
 
74
70
  export const loader = logto.handleAuthRoutes({
75
- "sign-in": {
76
- path: "/api/logto/sign-in",
77
- redirectBackTo: "/api/logto/callback",
71
+ 'sign-in': {
72
+ path: '/api/logto/sign-in',
73
+ redirectBackTo: '/api/logto/callback',
78
74
  },
79
- "sign-in-callback": {
80
- path: "/api/logto/callback",
81
- redirectBackTo: "/",
75
+ 'sign-in-callback': {
76
+ path: '/api/logto/callback',
77
+ redirectBackTo: '/',
82
78
  },
83
- "sign-out": {
84
- path: "/api/logto/sign-out",
85
- redirectBackTo: "/",
79
+ 'sign-out': {
80
+ path: '/api/logto/sign-out',
81
+ redirectBackTo: '/',
86
82
  },
87
- "sign-up": {
88
- path: "/api/logto/sign-up",
89
- redirectBackTo: "/api/logto/callback",
83
+ 'sign-up': {
84
+ path: '/api/logto/sign-up',
85
+ redirectBackTo: '/api/logto/callback',
90
86
  },
91
87
  });
92
88
  ```
@@ -101,23 +97,21 @@ A typical use case is to fetch the _authentication context_ which contains infor
101
97
 
102
98
  ```ts
103
99
  // app/routes/index.tsx
104
- import type { LogtoContext } from "@logto/remix";
105
- import { LoaderFunction, json } from "@remix-run/node";
106
- import { useLoaderData } from "@remix-run/react";
100
+ import type { LogtoContext } from '@logto/remix';
101
+ import { LoaderFunction, json } from '@remix-run/node';
102
+ import { useLoaderData } from '@remix-run/react';
107
103
 
108
- import { logto } from "~/services/authentication";
104
+ import { logto } from '../../service/auth.server';
109
105
 
110
106
  type LoaderResponse = {
111
107
  readonly context: LogtoContext;
112
108
  };
113
109
 
114
110
  export const loader: LoaderFunction = async ({ request }) => {
115
- const context = await logto.getContext({ getAccessToken: false })(
116
- request
117
- );
111
+ const context = await logto.getContext({ getAccessToken: false })(request);
118
112
 
119
113
  if (!context.isAuthenticated) {
120
- return redirect("/api/logto/sign-in");
114
+ return redirect('/api/logto/sign-in');
121
115
  }
122
116
 
123
117
  return json<LoaderResponse>({ context });
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@logto/remix",
3
- "version": "2.2.6",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
- "main": "./lib/index.cjs",
6
5
  "module": "./lib/index.js",
7
6
  "types": "./lib/index.d.ts",
8
7
  "exports": {
9
8
  "types": "./lib/index.d.ts",
10
- "require": "./lib/index.cjs",
11
9
  "import": "./lib/index.js",
12
10
  "default": "./lib/index.js"
13
11
  },
@@ -21,13 +19,13 @@
21
19
  "directory": "packages/remix"
22
20
  },
23
21
  "dependencies": {
24
- "@logto/node": "^2.5.7"
22
+ "@logto/node": "^3.0.3"
25
23
  },
26
24
  "devDependencies": {
27
25
  "@remix-run/node": "^2.0.0",
28
26
  "@silverhand/eslint-config": "^6.0.1",
29
27
  "@silverhand/ts-config": "^6.0.0",
30
- "@types/node": "^20.11.19",
28
+ "@types/node": "^22.0.0",
31
29
  "@vitest/coverage-v8": "^1.6.0",
32
30
  "eslint": "^8.57.0",
33
31
  "lint-staged": "^15.0.0",
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const getCookieHeaderFromRequest = (request) => request.headers.get('Cookie');
4
-
5
- exports.getCookieHeaderFromRequest = getCookieHeaderFromRequest;
package/lib/index.cjs DELETED
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- var index$2 = require('./infrastructure/logto/index.cjs');
4
- var index$1 = require('./useCases/getContext/index.cjs');
5
- var index = require('./useCases/handleAuthRoutes/index.cjs');
6
- var LogtoClient = require('@logto/node');
7
-
8
- const makeLogtoRemix = (config, deps) => {
9
- const { sessionStorage } = deps;
10
- const { baseUrl } = config;
11
- const createLogtoAdapter = index$2.makeLogtoAdapter(config);
12
- return Object.freeze({
13
- handleAuthRoutes: index.makeHandleAuthRoutes({
14
- baseUrl,
15
- createLogtoAdapter,
16
- sessionStorage,
17
- }),
18
- getContext: (dto) => index$1.makeGetContext(dto, {
19
- createLogtoAdapter,
20
- sessionStorage,
21
- }),
22
- });
23
- };
24
-
25
- Object.defineProperty(exports, "LogtoClientError", {
26
- enumerable: true,
27
- get: function () { return LogtoClient.LogtoClientError; }
28
- });
29
- Object.defineProperty(exports, "LogtoError", {
30
- enumerable: true,
31
- get: function () { return LogtoClient.LogtoError; }
32
- });
33
- Object.defineProperty(exports, "LogtoRequestError", {
34
- enumerable: true,
35
- get: function () { return LogtoClient.LogtoRequestError; }
36
- });
37
- Object.defineProperty(exports, "OidcError", {
38
- enumerable: true,
39
- get: function () { return LogtoClient.OidcError; }
40
- });
41
- Object.defineProperty(exports, "PersistKey", {
42
- enumerable: true,
43
- get: function () { return LogtoClient.PersistKey; }
44
- });
45
- Object.defineProperty(exports, "Prompt", {
46
- enumerable: true,
47
- get: function () { return LogtoClient.Prompt; }
48
- });
49
- Object.defineProperty(exports, "ReservedScope", {
50
- enumerable: true,
51
- get: function () { return LogtoClient.ReservedScope; }
52
- });
53
- Object.defineProperty(exports, "UserScope", {
54
- enumerable: true,
55
- get: function () { return LogtoClient.UserScope; }
56
- });
57
- Object.defineProperty(exports, "buildOrganizationUrn", {
58
- enumerable: true,
59
- get: function () { return LogtoClient.buildOrganizationUrn; }
60
- });
61
- Object.defineProperty(exports, "getOrganizationIdFromUrn", {
62
- enumerable: true,
63
- get: function () { return LogtoClient.getOrganizationIdFromUrn; }
64
- });
65
- Object.defineProperty(exports, "organizationUrnPrefix", {
66
- enumerable: true,
67
- get: function () { return LogtoClient.organizationUrnPrefix; }
68
- });
69
- exports.makeLogtoRemix = makeLogtoRemix;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- var LogtoClient = require('@logto/node');
4
-
5
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
-
7
- var LogtoClient__default = /*#__PURE__*/_interopDefault(LogtoClient);
8
-
9
- const makeLogtoClient = (config, storage) =>
10
- // Have to deactivate the eslint rule here as the `LogtoClient`
11
- // awaits a `navigate` function.
12
- // eslint-disable-next-line @typescript-eslint/no-empty-function
13
- (navigate = () => { }) => {
14
- return new LogtoClient__default.default(config, { storage, navigate });
15
- };
16
-
17
- exports.makeLogtoClient = makeLogtoClient;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- class LogtoStorage {
4
- static { this.fromSession = (session) => {
5
- return new LogtoStorage({ session });
6
- }; }
7
- constructor(properties) {
8
- this.properties = properties;
9
- this.session = this.properties.session;
10
- this.setItem = async (key, value) => {
11
- this.session.set(key, value);
12
- };
13
- this.getItem = async (key) => {
14
- const itemExists = this.session.has(key);
15
- if (!itemExists) {
16
- return null;
17
- }
18
- return String(this.session.get(key));
19
- };
20
- this.removeItem = async (key) => {
21
- this.session.unset(key);
22
- };
23
- this.save = async () => {
24
- // Not required as the persistence happens in the integration layer
25
- };
26
- }
27
- }
28
- const createStorage = (session) => LogtoStorage.fromSession(session);
29
-
30
- exports.createStorage = createStorage;
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const makeGetContext = (deps) => async (request) => {
4
- const { storage, createClient } = deps;
5
- const client = createClient();
6
- const context = await client.getContext(request);
7
- return {
8
- context,
9
- };
10
- };
11
-
12
- exports.makeGetContext = makeGetContext;
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const makeHandleSignInCallback = (deps) => async (request) => {
4
- const { storage, createClient } = deps;
5
- const client = createClient();
6
- await client.handleSignInCallback(request.callbackUri);
7
- return {
8
- session: storage.session,
9
- };
10
- };
11
-
12
- exports.makeHandleSignInCallback = makeHandleSignInCallback;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleSignInCommand {
4
- static { this.fromDependencies = (dependencies) => new HandleSignInCommand({ createClient: dependencies.createClient }); }
5
- constructor(properties) {
6
- this.properties = properties;
7
- this.navigateToUrl = '/api/sign-in';
8
- }
9
- async execute(request) {
10
- const { createClient } = this.properties;
11
- const client = createClient((url) => {
12
- this.navigateToUrl = url;
13
- });
14
- await client.signIn(request.redirectUri);
15
- return {
16
- navigateToUrl: this.navigateToUrl,
17
- };
18
- }
19
- }
20
- const makeHandleSignIn = (deps) => async (request) => {
21
- const { storage, createClient } = deps;
22
- const command = HandleSignInCommand.fromDependencies({ createClient });
23
- const { navigateToUrl } = await command.execute(request);
24
- return {
25
- session: storage.session,
26
- navigateToUrl,
27
- };
28
- };
29
-
30
- exports.makeHandleSignIn = makeHandleSignIn;
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleSignOutCommand {
4
- static { this.fromDependencies = (dependencies) => new HandleSignOutCommand({ createClient: dependencies.createClient }); }
5
- constructor(properties) {
6
- this.properties = properties;
7
- this.navigateToUrl = '/api/sign-in';
8
- }
9
- async execute(request) {
10
- const { createClient } = this.properties;
11
- const client = createClient((url) => {
12
- this.navigateToUrl = url;
13
- });
14
- await client.signOut(request.redirectUri);
15
- return {
16
- navigateToUrl: this.navigateToUrl,
17
- };
18
- }
19
- }
20
- const makeHandleSignOut = (deps) => async (request) => {
21
- const { createClient } = deps;
22
- const command = HandleSignOutCommand.fromDependencies({ createClient });
23
- return command.execute(request);
24
- };
25
-
26
- exports.makeHandleSignOut = makeHandleSignOut;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleSignUpCommand {
4
- static { this.fromDependencies = (dependencies) => new HandleSignUpCommand({ createClient: dependencies.createClient }); }
5
- constructor(properties) {
6
- this.properties = properties;
7
- this.navigateToUrl = '/api/sign-up';
8
- }
9
- async execute(request) {
10
- const { createClient } = this.properties;
11
- const client = createClient((url) => {
12
- this.navigateToUrl = url;
13
- });
14
- await client.signIn({ redirectUri: request.redirectUri, interactionMode: 'signUp' });
15
- return {
16
- navigateToUrl: this.navigateToUrl,
17
- };
18
- }
19
- }
20
- const makeHandleSignUp = (deps) => async (request) => {
21
- const { storage, createClient } = deps;
22
- const command = HandleSignUpCommand.fromDependencies({ createClient });
23
- const { navigateToUrl } = await command.execute(request);
24
- return {
25
- session: storage.session,
26
- navigateToUrl,
27
- };
28
- };
29
-
30
- exports.makeHandleSignUp = makeHandleSignUp;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var createClient = require('./create-client.cjs');
4
- var createStorage = require('./create-storage.cjs');
5
- var getContext = require('./get-context.cjs');
6
- var handleSignInCallback = require('./handle-sign-in-callback.cjs');
7
- var handleSignIn = require('./handle-sign-in.cjs');
8
- var handleSignOut = require('./handle-sign-out.cjs');
9
- var handleSignUp = require('./handle-sign-up.cjs');
10
-
11
- const makeLogtoAdapter = (config) => (session) => {
12
- const storage = createStorage.createStorage(session);
13
- const createClient$1 = createClient.makeLogtoClient(config, storage);
14
- return {
15
- handleSignIn: handleSignIn.makeHandleSignIn({ storage, createClient: createClient$1 }),
16
- handleSignInCallback: handleSignInCallback.makeHandleSignInCallback({ storage, createClient: createClient$1 }),
17
- handleSignOut: handleSignOut.makeHandleSignOut({ createClient: createClient$1 }),
18
- handleSignUp: handleSignUp.makeHandleSignUp({ storage, createClient: createClient$1 }),
19
- getContext: getContext.makeGetContext({ storage, createClient: createClient$1 }),
20
- };
21
- };
22
-
23
- exports.makeLogtoAdapter = makeLogtoAdapter;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
4
-
5
- class GetContextController {
6
- static { this.fromDto = (dto) => new GetContextController(dto); }
7
- constructor(properties) {
8
- this.properties = properties;
9
- this.useCase = this.properties.useCase;
10
- this.execute = async (request) => {
11
- const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
12
- const result = await this.useCase({
13
- cookieHeader: cookieHeader ?? undefined,
14
- ...this.properties,
15
- });
16
- return result.context;
17
- };
18
- }
19
- }
20
-
21
- exports.GetContextController = GetContextController;
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- const makeGetContextUseCase = (deps) => async (request) => {
4
- const { sessionStorage, createLogtoAdapter } = deps;
5
- const session = await sessionStorage.getSession(request.cookieHeader);
6
- const logto = createLogtoAdapter(session);
7
- const response = await logto.getContext(request);
8
- return {
9
- context: response.context,
10
- };
11
- };
12
-
13
- exports.makeGetContextUseCase = makeGetContextUseCase;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var GetContextController = require('./GetContextController.cjs');
4
- var GetContextUseCase = require('./GetContextUseCase.cjs');
5
-
6
- const makeGetContext = (dto, deps) => async (request) => {
7
- const { createLogtoAdapter, sessionStorage } = deps;
8
- const useCase = GetContextUseCase.makeGetContextUseCase({
9
- createLogtoAdapter,
10
- sessionStorage,
11
- });
12
- const controller = GetContextController.GetContextController.fromDto({
13
- useCase,
14
- ...dto,
15
- });
16
- return controller.execute(request);
17
- };
18
-
19
- exports.makeGetContext = makeGetContext;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleAuthRoutesError extends Error {
4
- static { this.becauseNoConfigForPath = (anticipatedPath) => new HandleAuthRoutesError({
5
- code: 1_665_388_277,
6
- message: `No configuration available for path "${anticipatedPath}".`,
7
- }); }
8
- static { this.becauseOfUnknownRoute = (anticipatedConfigKey) => new HandleAuthRoutesError({
9
- code: 1_665_388_278,
10
- message: `The config key "${anticipatedConfigKey}" is invalid.`,
11
- }); }
12
- constructor(properties) {
13
- super(`#[${properties.code}] ${properties.message}`);
14
- this.properties = properties;
15
- this.code = this.properties.code;
16
- this.cause = this.properties.cause;
17
- this.plainMessage = this.properties.message;
18
- }
19
- }
20
-
21
- exports.HandleAuthRoutesError = HandleAuthRoutesError;
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var index$3 = require('../handleSignIn/index.cjs');
4
- var index$2 = require('../handleSignInCallback/index.cjs');
5
- var index = require('../handleSignOut/index.cjs');
6
- var index$1 = require('../handleSignUp/index.cjs');
7
- var HandleAuthRoutesError = require('./HandleAuthRoutesError.cjs');
8
-
9
- const makeHandleAuthRoutes = (deps) => (dto) => async ({ request }) => {
10
- const anticipatedPath = new URL(request.url).pathname;
11
- /* eslint-disable no-restricted-syntax */
12
- const configKey = Object.keys(dto).find((type) => dto[type].path === anticipatedPath);
13
- const configExists = Boolean(configKey);
14
- /* eslint-enable no-restricted-syntax */
15
- if (!configExists) {
16
- throw HandleAuthRoutesError.HandleAuthRoutesError.becauseNoConfigForPath(anticipatedPath);
17
- }
18
- const { sessionStorage, createLogtoAdapter, baseUrl } = deps;
19
- const config = dto[configKey];
20
- switch (configKey) {
21
- case 'sign-in': {
22
- const handler = index$3.makeHandleSignIn({
23
- redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
24
- }, { sessionStorage, createLogtoAdapter });
25
- return handler(request);
26
- }
27
- case 'sign-in-callback': {
28
- const handler = index$2.makeHandleSignInCallback({
29
- redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
30
- }, { sessionStorage, createLogtoAdapter });
31
- return handler(request);
32
- }
33
- case 'sign-up': {
34
- const handler = index$1.makeHandleSignUp({
35
- redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
36
- }, { sessionStorage, createLogtoAdapter });
37
- return handler(request);
38
- }
39
- case 'sign-out': {
40
- const handler = index.makeHandleSignOut({
41
- redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
42
- }, { sessionStorage, createLogtoAdapter });
43
- return handler(request);
44
- }
45
- }
46
- };
47
-
48
- exports.makeHandleAuthRoutes = makeHandleAuthRoutes;
@@ -1,31 +0,0 @@
1
- 'use strict';
2
-
3
- var node = require('@remix-run/node');
4
- var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
5
-
6
- class HandleSignInController {
7
- static { this.fromDto = (dto) => new HandleSignInController({
8
- useCase: dto.useCase,
9
- redirectUri: dto.redirectUri,
10
- }); }
11
- constructor(properties) {
12
- this.properties = properties;
13
- this.useCase = this.properties.useCase;
14
- this.redirectUri = this.properties.redirectUri;
15
- this.execute = async (request) => {
16
- const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
17
- const { redirectUri } = this;
18
- const result = await this.useCase({
19
- cookieHeader: cookieHeader ?? undefined,
20
- redirectUri,
21
- });
22
- return node.redirect(result.navigateToUrl, {
23
- headers: {
24
- 'Set-Cookie': result.cookieHeader,
25
- },
26
- });
27
- };
28
- }
29
- }
30
-
31
- exports.HandleSignInController = HandleSignInController;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- const makeHandleSignInUseCase = (deps) => async (request) => {
4
- const { sessionStorage, createLogtoAdapter } = deps;
5
- const session = await sessionStorage.getSession(request.cookieHeader);
6
- const logto = createLogtoAdapter(session);
7
- const response = await logto.handleSignIn({
8
- redirectUri: request.redirectUri,
9
- });
10
- const cookieHeader = await sessionStorage.commitSession(response.session);
11
- return {
12
- cookieHeader,
13
- navigateToUrl: response.navigateToUrl,
14
- };
15
- };
16
-
17
- exports.makeHandleSignInUseCase = makeHandleSignInUseCase;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var HandleSignInController = require('./HandleSignInController.cjs');
4
- var HandleSignInUseCase = require('./HandleSignInUseCase.cjs');
5
-
6
- const makeHandleSignIn = (dto, deps) => async (request) => {
7
- const { createLogtoAdapter, sessionStorage } = deps;
8
- const useCase = HandleSignInUseCase.makeHandleSignInUseCase({
9
- createLogtoAdapter,
10
- sessionStorage,
11
- });
12
- const controller = HandleSignInController.HandleSignInController.fromDto({
13
- useCase,
14
- redirectUri: dto.redirectBackTo,
15
- });
16
- return controller.execute(request);
17
- };
18
-
19
- exports.makeHandleSignIn = makeHandleSignIn;
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- var node = require('@remix-run/node');
4
- var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
5
- var HandleSignInCallbackError = require('./HandleSignInCallbackError.cjs');
6
-
7
- class HandleSignInCallbackController {
8
- static { this.fromDto = (dto) => new HandleSignInCallbackController({
9
- useCase: dto.useCase,
10
- redirectUri: dto.redirectUri,
11
- }); }
12
- constructor(properties) {
13
- this.properties = properties;
14
- this.useCase = this.properties.useCase;
15
- this.redirectUri = this.properties.redirectUri;
16
- this.execute = async (request) => {
17
- const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
18
- if (!cookieHeader) {
19
- throw HandleSignInCallbackError.HandleSignInCallbackError.becauseNoCookieHeaderPresent();
20
- }
21
- // In some scenarios, like performing the sign-in callback within a Gitpod
22
- // environment, the load balancer rewrites the URL and uses `http` as the
23
- // protocol. Here, we make sure that when the `x-forwarded-proto` HTTP header
24
- // is present, we will replace `http` with `https` in the `callbackUri`.
25
- const isForwardedHttpsTraffic = request.headers.get('x-forwarded-proto') === 'https';
26
- const callbackUri = isForwardedHttpsTraffic
27
- ? request.url.replace('http', 'https')
28
- : request.url;
29
- const result = await this.useCase({
30
- cookieHeader,
31
- callbackUri,
32
- });
33
- return node.redirect(this.redirectUri, {
34
- headers: {
35
- 'Set-Cookie': result.cookieHeader,
36
- },
37
- });
38
- };
39
- }
40
- }
41
-
42
- exports.HandleSignInCallbackController = HandleSignInCallbackController;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleSignInCallbackError extends Error {
4
- static { this.becauseNoCookieHeaderPresent = () => new HandleSignInCallbackError({
5
- code: 1_665_388_541,
6
- message: `The authentication sign-in callback route can't be accessed without a valid cookie.`,
7
- }); }
8
- constructor(properties) {
9
- super(`#[${properties.code}] ${properties.message}`);
10
- this.properties = properties;
11
- this.code = this.properties.code;
12
- this.cause = this.properties.cause;
13
- this.plainMessage = this.properties.message;
14
- }
15
- }
16
-
17
- exports.HandleSignInCallbackError = HandleSignInCallbackError;
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const makeHandleSignInCallbackUseCase = (deps) => async (request) => {
4
- const { sessionStorage, createLogtoAdapter } = deps;
5
- const session = await sessionStorage.getSession(request.cookieHeader);
6
- const logto = createLogtoAdapter(session);
7
- const response = await logto.handleSignInCallback({
8
- callbackUri: request.callbackUri,
9
- });
10
- const cookieHeader = await sessionStorage.commitSession(response.session);
11
- return {
12
- cookieHeader,
13
- };
14
- };
15
-
16
- exports.makeHandleSignInCallbackUseCase = makeHandleSignInCallbackUseCase;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var HandleSignInCallbackController = require('./HandleSignInCallbackController.cjs');
4
- var HandleSignInCallbackUseCase = require('./HandleSignInCallbackUseCase.cjs');
5
-
6
- const makeHandleSignInCallback = (dto, deps) => async (request) => {
7
- const { createLogtoAdapter, sessionStorage } = deps;
8
- const useCase = HandleSignInCallbackUseCase.makeHandleSignInCallbackUseCase({
9
- createLogtoAdapter,
10
- sessionStorage,
11
- });
12
- const controller = HandleSignInCallbackController.HandleSignInCallbackController.fromDto({
13
- useCase,
14
- redirectUri: dto.redirectBackTo,
15
- });
16
- return controller.execute(request);
17
- };
18
-
19
- exports.makeHandleSignInCallback = makeHandleSignInCallback;
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- var node = require('@remix-run/node');
4
- var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
5
- var HandleSignOutError = require('./HandleSignOutError.cjs');
6
-
7
- class HandleSignOutController {
8
- static { this.fromDto = (dto) => new HandleSignOutController({
9
- useCase: dto.useCase,
10
- redirectUri: dto.redirectUri,
11
- }); }
12
- constructor(properties) {
13
- this.properties = properties;
14
- this.useCase = this.properties.useCase;
15
- this.redirectUri = this.properties.redirectUri;
16
- this.execute = async (request) => {
17
- const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
18
- if (!cookieHeader) {
19
- throw HandleSignOutError.HandleSignOutError.becauseNoCookieHeaderPresent();
20
- }
21
- const result = await this.useCase({
22
- cookieHeader,
23
- redirectUri: this.redirectUri,
24
- });
25
- return node.redirect(result.navigateToUrl, {
26
- headers: {
27
- 'Set-Cookie': result.cookieHeader,
28
- },
29
- });
30
- };
31
- }
32
- }
33
-
34
- exports.HandleSignOutController = HandleSignOutController;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- class HandleSignOutError extends Error {
4
- static { this.becauseNoCookieHeaderPresent = () => new HandleSignOutError({
5
- code: 1_665_388_713,
6
- message: `The authentication sign-out route can't be accessed without a valid cookie.`,
7
- }); }
8
- constructor(properties) {
9
- super(`#[${properties.code}] ${properties.message}`);
10
- this.properties = properties;
11
- this.code = this.properties.code;
12
- this.cause = this.properties.cause;
13
- this.plainMessage = this.properties.message;
14
- }
15
- }
16
-
17
- exports.HandleSignOutError = HandleSignOutError;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- const makeHandleSignOutUseCase = (deps) => async (request) => {
4
- const { sessionStorage, createLogtoAdapter } = deps;
5
- const session = await sessionStorage.getSession(request.cookieHeader);
6
- const logto = createLogtoAdapter(session);
7
- const response = await logto.handleSignOut({
8
- redirectUri: request.redirectUri,
9
- });
10
- const cookieHeader = await sessionStorage.destroySession(session);
11
- return {
12
- cookieHeader,
13
- navigateToUrl: response.navigateToUrl,
14
- };
15
- };
16
-
17
- exports.makeHandleSignOutUseCase = makeHandleSignOutUseCase;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var HandleSignOutController = require('./HandleSignOutController.cjs');
4
- var HandleSignOutUseCase = require('./HandleSignOutUseCase.cjs');
5
-
6
- const makeHandleSignOut = (dto, deps) => async (request) => {
7
- const { createLogtoAdapter, sessionStorage } = deps;
8
- const useCase = HandleSignOutUseCase.makeHandleSignOutUseCase({
9
- createLogtoAdapter,
10
- sessionStorage,
11
- });
12
- const controller = HandleSignOutController.HandleSignOutController.fromDto({
13
- useCase,
14
- redirectUri: dto.redirectBackTo,
15
- });
16
- return controller.execute(request);
17
- };
18
-
19
- exports.makeHandleSignOut = makeHandleSignOut;
@@ -1,31 +0,0 @@
1
- 'use strict';
2
-
3
- var node = require('@remix-run/node');
4
- var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
5
-
6
- class HandleSignUpController {
7
- static { this.fromDto = (dto) => new HandleSignUpController({
8
- useCase: dto.useCase,
9
- redirectUri: dto.redirectUri,
10
- }); }
11
- constructor(properties) {
12
- this.properties = properties;
13
- this.useCase = this.properties.useCase;
14
- this.redirectUri = this.properties.redirectUri;
15
- this.execute = async (request) => {
16
- const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
17
- const { redirectUri } = this;
18
- const result = await this.useCase({
19
- cookieHeader: cookieHeader ?? undefined,
20
- redirectUri,
21
- });
22
- return node.redirect(result.navigateToUrl, {
23
- headers: {
24
- 'Set-Cookie': result.cookieHeader,
25
- },
26
- });
27
- };
28
- }
29
- }
30
-
31
- exports.HandleSignUpController = HandleSignUpController;
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- const makeHandleSignUpUseCase = (deps) => async (request) => {
4
- const { sessionStorage, createLogtoAdapter } = deps;
5
- const session = await sessionStorage.getSession(request.cookieHeader);
6
- const logto = createLogtoAdapter(session);
7
- const response = await logto.handleSignUp({
8
- redirectUri: request.redirectUri,
9
- });
10
- const cookieHeader = await sessionStorage.commitSession(response.session);
11
- return {
12
- cookieHeader,
13
- navigateToUrl: response.navigateToUrl,
14
- };
15
- };
16
-
17
- exports.makeHandleSignUpUseCase = makeHandleSignUpUseCase;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var HandleSignUpController = require('./HandleSignUpController.cjs');
4
- var HandleSignUpUseCase = require('./HandleSignUpUseCase.cjs');
5
-
6
- const makeHandleSignUp = (dto, deps) => async (request) => {
7
- const { createLogtoAdapter, sessionStorage } = deps;
8
- const useCase = HandleSignUpUseCase.makeHandleSignUpUseCase({
9
- createLogtoAdapter,
10
- sessionStorage,
11
- });
12
- const controller = HandleSignUpController.HandleSignUpController.fromDto({
13
- useCase,
14
- redirectUri: dto.redirectBackTo,
15
- });
16
- return controller.execute(request);
17
- };
18
-
19
- exports.makeHandleSignUp = makeHandleSignUp;