@adonisjs/auth 10.0.0-next.6 → 10.1.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.
@@ -1,12 +1,32 @@
1
- import "../errors-Ns_FO2np.js";
2
- import "../debug-Ckko95-M.js";
3
- import { t as AuthManager } from "../auth_manager-CJvMGOzX.js";
1
+ import { t as AuthManager } from "../auth_manager-Cp_ofh4p.js";
4
2
  import { RuntimeException } from "@adonisjs/core/exceptions";
5
3
  import { configProvider } from "@adonisjs/core";
4
+ //#region providers/auth_provider.ts
5
+ /**
6
+ * The AuthProvider service provider registers the auth manager
7
+ * with the IoC container as a singleton
8
+ *
9
+ * @example
10
+ * // The auth manager is automatically registered and can be injected
11
+ * container.use('auth.manager')
12
+ */
6
13
  var AuthProvider = class {
14
+ /**
15
+ * Creates a new AuthProvider instance
16
+ *
17
+ * @param app - The application service instance
18
+ */
7
19
  constructor(app) {
8
20
  this.app = app;
9
21
  }
22
+ /**
23
+ * Registers the auth manager as a singleton service
24
+ * in the IoC container
25
+ *
26
+ * @example
27
+ * // This method is called automatically by AdonisJS
28
+ * // The auth manager becomes available as 'auth.manager'
29
+ */
10
30
  register() {
11
31
  this.app.container.singleton("auth.manager", async () => {
12
32
  const authConfigProvider = this.app.config.get("auth");
@@ -16,4 +36,5 @@ var AuthProvider = class {
16
36
  });
17
37
  }
18
38
  };
39
+ //#endregion
19
40
  export { AuthProvider as default };
@@ -1,6 +1,11 @@
1
1
  import app from "@adonisjs/core/services/app";
2
+ //#region services/auth.ts
2
3
  let auth;
4
+ /**
5
+ * Returns a singleton instance of the Auth manager class
6
+ */
3
7
  await app.booted(async () => {
4
8
  auth = await app.container.make("auth.manager");
5
9
  });
10
+ //#endregion
6
11
  export { auth as default };
@@ -1,8 +1,37 @@
1
+ //#region src/middleware/initialize_auth_middleware.ts
2
+ /**
3
+ * The "InitializeAuthMiddleware" is used to create a request
4
+ * specific authenticator instance for every HTTP request.
5
+ *
6
+ * This middleware does not protect routes from unauthenticated
7
+ * users. Please use the "auth" middleware for that.
8
+ *
9
+ * @example
10
+ * router.use([() => import('#middleware/initialize_auth_middleware')])
11
+ */
1
12
  var InitializeAuthMiddleware = class {
13
+ /**
14
+ * Handle the HTTP request by initializing the authenticator
15
+ *
16
+ * @param ctx - The HTTP context
17
+ * @param next - The next function to call in the middleware chain
18
+ *
19
+ * @example
20
+ * // This middleware runs automatically when registered
21
+ * // It adds ctx.auth to every HTTP request
22
+ */
2
23
  async handle(ctx, next) {
24
+ /**
25
+ * Initialize the authenticator for the current HTTP
26
+ * request
27
+ */
3
28
  ctx.auth = (await ctx.containerResolver.make("auth.manager")).createAuthenticator(ctx);
29
+ /**
30
+ * Sharing authenticator with templates
31
+ */
4
32
  if ("view" in ctx) ctx.view.share({ auth: ctx.auth });
5
33
  return next();
6
34
  }
7
35
  };
36
+ //#endregion
8
37
  export { InitializeAuthMiddleware as default };
@@ -1,12 +1,39 @@
1
- import { t as E_INVALID_CREDENTIALS } from "../../errors-Ns_FO2np.js";
1
+ import { t as E_INVALID_CREDENTIALS } from "../../errors-eDV8ejO0.js";
2
2
  import { RuntimeException } from "@adonisjs/core/exceptions";
3
3
  import { beforeSave } from "@adonisjs/lucid/orm";
4
+ //#region \0@oxc-project+runtime@0.122.0/helpers/decorate.js
4
5
  function __decorate(decorators, target, key, desc) {
5
6
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
7
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
8
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
9
  return c > 3 && r && Object.defineProperty(target, key, r), r;
9
10
  }
11
+ //#endregion
12
+ //#region src/mixins/lucid.ts
13
+ /**
14
+ * Mixing to add user lookup and password verification methods
15
+ * on a model.
16
+ *
17
+ * Under the hood, this mixin defines following methods and hooks
18
+ *
19
+ * - beforeSave hook to hash user password
20
+ * - findForAuth method to find a user during authentication
21
+ * - verifyCredentials method to verify user credentials and prevent
22
+ * timing attacks.
23
+ *
24
+ * @param hash - Function that returns a Hash instance for password hashing
25
+ * @param options - Configuration options with uids and password column name
26
+ *
27
+ * @example
28
+ * import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
29
+ *
30
+ * class User extends withAuthFinder(hash, {
31
+ * uids: ['email', 'username'],
32
+ * passwordColumnName: 'password'
33
+ * })(BaseModel) {
34
+ * // User model implementation
35
+ * }
36
+ */
10
37
  function withAuthFinder(hash, options) {
11
38
  let normalizedOptions = {
12
39
  uids: ["email"],
@@ -16,15 +43,54 @@ function withAuthFinder(hash, options) {
16
43
  let hashFactory = typeof hash === "function" ? hash : () => hash.use();
17
44
  return function(superclass) {
18
45
  class UserWithUserFinder extends superclass {
46
+ /**
47
+ * Hook to hash user password when creating or updating
48
+ * the user model.
49
+ *
50
+ * @param user - The user instance being saved
51
+ *
52
+ * @example
53
+ * // This hook runs automatically before saving
54
+ * const user = new User()
55
+ * user.password = 'plaintext'
56
+ * await user.save() // password will be hashed automatically
57
+ */
19
58
  static async hashPassword(user) {
20
59
  if (user.$dirty[normalizedOptions.passwordColumnName]) user[normalizedOptions.passwordColumnName] = await hashFactory().make(user[normalizedOptions.passwordColumnName]);
21
60
  }
61
+ /**
62
+ * Finds the user for authentication via "verifyCredentials".
63
+ * Feel free to override this method to customize the user
64
+ * lookup behavior.
65
+ *
66
+ * @param uids - Array of column names to search in
67
+ * @param value - The value to search for
68
+ *
69
+ * @example
70
+ * const user = await User.findForAuth(['email', 'username'], 'john@example.com')
71
+ */
22
72
  static findForAuth(uids, value) {
23
73
  const query = this.query();
24
74
  uids.forEach((uid) => query.orWhere(uid, value));
25
75
  return query.limit(1).first();
26
76
  }
77
+ /**
78
+ * Find a user by uid and verify their password. This method is
79
+ * safe from timing attacks.
80
+ *
81
+ * @param uid - The user identifier (email, username, etc.)
82
+ * @param password - The plain text password to verify
83
+ *
84
+ * @throws {E_INVALID_CREDENTIALS} When credentials are invalid
85
+ *
86
+ * @example
87
+ * const user = await User.verifyCredentials('john@example.com', 'password123')
88
+ * console.log('Authenticated user:', user.email)
89
+ */
27
90
  static async verifyCredentials(uid, password) {
91
+ /**
92
+ * Fail when uid or the password are missing
93
+ */
28
94
  if (!uid || !password) throw new E_INVALID_CREDENTIALS("Invalid user credentials");
29
95
  const user = await this.findForAuth(normalizedOptions.uids, uid);
30
96
  if (!user) {
@@ -34,11 +100,37 @@ function withAuthFinder(hash, options) {
34
100
  if (await user.verifyPassword(password)) return user;
35
101
  throw new E_INVALID_CREDENTIALS("Invalid user credentials");
36
102
  }
103
+ /**
104
+ * Verifies the plain password against the user's password
105
+ * hash
106
+ *
107
+ * @param plainPassword - The plain text password to verify
108
+ *
109
+ * @throws {RuntimeException} When password column value is undefined or null
110
+ *
111
+ * @example
112
+ * const isValid = await user.verifyPassword('password123')
113
+ * if (isValid) {
114
+ * console.log('Password is correct')
115
+ * }
116
+ */
37
117
  verifyPassword(plainPassword) {
38
118
  const passwordHash = this[normalizedOptions.passwordColumnName];
39
119
  if (!passwordHash) throw new RuntimeException(`Cannot verify password. The value for "${normalizedOptions.passwordColumnName}" column is undefined or null`);
40
120
  return hashFactory().verify(passwordHash, plainPassword);
41
121
  }
122
+ /**
123
+ * Validates a plain password against the user's stored password hash.
124
+ * Throws a validation error if the password doesn't match.
125
+ *
126
+ * @param plainPassword - The plain text password to validate
127
+ * @param passwordFieldName - Optional field name for the error message (defaults to 'currentPassword')
128
+ *
129
+ * @throws {ValidationError} When the password is incorrect
130
+ *
131
+ * @example
132
+ * await user.validatePassword('oldPassword123', 'currentPassword')
133
+ */
42
134
  async validatePassword(plainPassword, passwordFieldName) {
43
135
  if (!await this.verifyPassword(plainPassword)) {
44
136
  const error = /* @__PURE__ */ new Error("Validation Error");
@@ -57,4 +149,5 @@ function withAuthFinder(hash, options) {
57
149
  return UserWithUserFinder;
58
150
  };
59
151
  }
152
+ //#endregion
60
153
  export { withAuthFinder };
@@ -1,8 +1,26 @@
1
- import { t as debug_default } from "../../../debug-Ckko95-M.js";
1
+ import { t as debug_default } from "../../../debug-CrTUB4zl.js";
2
2
  import { ApiClient, ApiRequest } from "@japa/api-client";
3
+ //#region src/plugins/japa/api_client.ts
4
+ /**
5
+ * Auth API client to authenticate users when making
6
+ * HTTP requests using the Japa API client
7
+ *
8
+ * @param app - The AdonisJS application service instance
9
+ *
10
+ * @example
11
+ * import { authApiClient } from '@adonisjs/auth/plugins/japa/api_client'
12
+ *
13
+ * export const plugins: PluginFn[] = [
14
+ * authApiClient(app)
15
+ * ]
16
+ */
3
17
  const authApiClient = (app) => {
4
18
  const pluginFn = function() {
5
19
  debug_default("installing auth api client plugin");
20
+ /**
21
+ * Login a user using the default authentication guard
22
+ * when making an API call
23
+ */
6
24
  ApiRequest.macro("loginAs", function(user, ...args) {
7
25
  this.authData = {
8
26
  guard: "__default__",
@@ -10,6 +28,9 @@ const authApiClient = (app) => {
10
28
  };
11
29
  return this;
12
30
  });
31
+ /**
32
+ * Define the authentication guard for login
33
+ */
13
34
  ApiRequest.macro("withGuard", function(guard) {
14
35
  return { loginAs: (...args) => {
15
36
  this.authData = {
@@ -19,6 +40,9 @@ const authApiClient = (app) => {
19
40
  return this;
20
41
  } };
21
42
  });
43
+ /**
44
+ * Hook into the request and login the user
45
+ */
22
46
  ApiClient.setup(async (request) => {
23
47
  const auth = await app.container.make("auth.manager");
24
48
  const authData = request["authData"];
@@ -42,4 +66,5 @@ const authApiClient = (app) => {
42
66
  };
43
67
  return pluginFn;
44
68
  };
69
+ //#endregion
45
70
  export { authApiClient };
@@ -1,11 +1,29 @@
1
- import { t as debug_default } from "../../../debug-Ckko95-M.js";
1
+ import { t as debug_default } from "../../../debug-CrTUB4zl.js";
2
2
  import { RuntimeException } from "@adonisjs/core/exceptions";
3
3
  import { decoratorsCollection } from "@japa/browser-client";
4
+ //#region src/plugins/japa/browser_client.ts
5
+ /**
6
+ * Browser API client to authenticate users when making
7
+ * HTTP requests using the Japa Browser client.
8
+ *
9
+ * @param app - The AdonisJS application service instance
10
+ *
11
+ * @example
12
+ * import { authBrowserClient } from '@adonisjs/auth/plugins/japa/browser_client'
13
+ *
14
+ * export const plugins: PluginFn[] = [
15
+ * authBrowserClient(app)
16
+ * ]
17
+ */
4
18
  const authBrowserClient = (app) => {
5
19
  const pluginFn = async function() {
6
20
  debug_default("installing auth browser client plugin");
7
21
  const auth = await app.container.make("auth.manager");
8
22
  decoratorsCollection.register({ context(context) {
23
+ /**
24
+ * Define the authentication guard for login and perform
25
+ * login
26
+ */
9
27
  context.withGuard = function(guardName) {
10
28
  return { async loginAs(...args) {
11
29
  const guard = auth.createAuthenticatorClient().use(guardName);
@@ -24,6 +42,10 @@ const authBrowserClient = (app) => {
24
42
  }
25
43
  } };
26
44
  };
45
+ /**
46
+ * Login a user using the default authentication guard when
47
+ * using the browser context to make page visits
48
+ */
27
49
  context.loginAs = async function(user, ...args) {
28
50
  const guard = auth.createAuthenticatorClient().use();
29
51
  const requestData = await guard.authenticateAsClient(user, ...args);
@@ -44,4 +66,5 @@ const authBrowserClient = (app) => {
44
66
  };
45
67
  return pluginFn;
46
68
  };
69
+ //#endregion
47
70
  export { authBrowserClient };
@@ -1,8 +1,17 @@
1
- import { i as __exportAll } from "./errors-Ns_FO2np.js";
1
+ import { i as __exportAll } from "./errors-eDV8ejO0.js";
2
+ //#region src/symbols.ts
2
3
  var symbols_exports = /* @__PURE__ */ __exportAll({
3
4
  GUARD_KNOWN_EVENTS: () => GUARD_KNOWN_EVENTS,
4
5
  PROVIDER_REAL_USER: () => PROVIDER_REAL_USER
5
6
  });
7
+ /**
8
+ * A symbol to identify the type of the real user for a given
9
+ * user provider
10
+ */
6
11
  const PROVIDER_REAL_USER = Symbol.for("PROVIDER_REAL_USER");
12
+ /**
13
+ * A symbol to identify the type for the events emitted by a guard
14
+ */
7
15
  const GUARD_KNOWN_EVENTS = Symbol.for("GUARD_KNOWN_EVENTS");
16
+ //#endregion
8
17
  export { symbols_exports as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/auth",
3
3
  "description": "Official authentication provider for Adonis framework",
4
- "version": "10.0.0-next.6",
4
+ "version": "10.1.0",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "scripts": {
33
33
  "pretest": "npm run lint",
34
- "test": "npm run test:mysql && npm run test:pg && npm run test:mssql && c8 npm run test:sqlite",
34
+ "test": "npm run test:mysql && npm run test:pg && npm run test:mssql && npm run test:sqlite",
35
35
  "test:sqlite": "npm run quick:test",
36
36
  "test:mysql": "cross-env DB=mysql npm run quick:test",
37
37
  "test:mssql": "cross-env DB=mssql npm run quick:test",
@@ -51,64 +51,64 @@
51
51
  "quick:test": "cross-env NODE_DEBUG=\"adonisjs:auth:*\" node --enable-source-maps --import=@poppinss/ts-exec ./bin/test.js"
52
52
  },
53
53
  "devDependencies": {
54
- "@adonisjs/assembler": "^8.0.0-next.30",
55
- "@adonisjs/core": "^7.0.0-next.25",
56
- "@adonisjs/eslint-config": "^3.0.0-next.9",
57
- "@adonisjs/i18n": "^3.0.0-next.2",
58
- "@adonisjs/lucid": "^22.0.0-next.7",
54
+ "@adonisjs/assembler": "^8.4.0",
55
+ "@adonisjs/core": "^7.3.1",
56
+ "@adonisjs/eslint-config": "^3.0.0",
57
+ "@adonisjs/i18n": "^3.0.0",
58
+ "@adonisjs/lucid": "^22.4.2",
59
59
  "@adonisjs/prettier-config": "^1.4.5",
60
- "@adonisjs/session": "^8.0.0-next.2",
61
- "@adonisjs/tsconfig": "^2.0.0-next.3",
60
+ "@adonisjs/session": "^8.1.0",
61
+ "@adonisjs/tsconfig": "^2.0.0",
62
62
  "@japa/api-client": "^3.2.1",
63
63
  "@japa/assert": "^4.2.0",
64
64
  "@japa/browser-client": "^2.3.0",
65
65
  "@japa/expect-type": "^2.0.4",
66
66
  "@japa/file-system": "^3.0.0",
67
- "@japa/plugin-adonisjs": "^5.1.0-next.0",
67
+ "@japa/plugin-adonisjs": "^5.2.0",
68
68
  "@japa/runner": "^5.3.0",
69
69
  "@japa/snapshot": "^2.0.10",
70
- "@poppinss/ts-exec": "^1.4.2",
71
- "@release-it/conventional-changelog": "^10.0.4",
70
+ "@poppinss/ts-exec": "^1.4.4",
71
+ "@release-it/conventional-changelog": "^10.0.6",
72
72
  "@types/basic-auth": "^1.1.8",
73
73
  "@types/luxon": "^3.7.1",
74
- "@types/node": "^25.0.10",
74
+ "@types/node": "^25.5.2",
75
75
  "@types/set-cookie-parser": "^2.4.10",
76
- "@types/sinon": "^21.0.0",
77
- "better-sqlite3": "^12.6.2",
78
- "c8": "^10.1.3",
76
+ "@types/sinon": "^21.0.1",
77
+ "better-sqlite3": "^12.8.0",
78
+ "c8": "^11.0.0",
79
79
  "convert-hrtime": "^5.0.0",
80
80
  "copyfiles": "^2.4.1",
81
81
  "cross-env": "^10.1.0",
82
82
  "del-cli": "^7.0.0",
83
- "dotenv": "^17.2.3",
84
- "eslint": "^9.39.2",
83
+ "dotenv": "^17.4.1",
84
+ "eslint": "^10.2.0",
85
85
  "luxon": "^3.7.2",
86
- "mysql2": "^3.16.1",
87
- "nock": "^14.0.10",
88
- "pg": "^8.17.2",
89
- "playwright": "^1.57.0",
86
+ "mysql2": "^3.21.0",
87
+ "nock": "^14.0.12",
88
+ "pg": "^8.20.0",
89
+ "playwright": "^1.59.1",
90
90
  "prettier": "^3.8.1",
91
91
  "release-it": "^19.2.4",
92
- "set-cookie-parser": "^3.0.1",
93
- "sinon": "^21.0.1",
94
- "tedious": "^19.2.0",
92
+ "set-cookie-parser": "^3.1.0",
93
+ "sinon": "^21.0.3",
94
+ "tedious": "^19.2.1",
95
95
  "timekeeper": "^2.3.1",
96
- "tsdown": "^0.19.0",
97
- "typescript": "^5.9.3"
96
+ "tsdown": "^0.21.7",
97
+ "typescript": "^6.0.2"
98
98
  },
99
99
  "dependencies": {
100
- "@adonisjs/presets": "^3.0.0-next.1",
100
+ "@adonisjs/presets": "^3.0.0",
101
101
  "basic-auth": "^2.0.1"
102
102
  },
103
103
  "peerDependencies": {
104
- "@adonisjs/assembler": "^8.0.0-next.26",
105
- "@adonisjs/core": "^7.0.0-next.16",
106
- "@adonisjs/i18n": "^3.0.0-next.2",
107
- "@adonisjs/lucid": "^22.0.0-next.1",
108
- "@adonisjs/session": "^8.0.0-next.1",
104
+ "@adonisjs/assembler": "^8.0.0-next.26 || ^8.0.0",
105
+ "@adonisjs/core": "^7.0.0-next.16 || ^7.0.0",
106
+ "@adonisjs/i18n": "^3.0.0-next.2 || ^3.0.0",
107
+ "@adonisjs/lucid": "^22.0.0-next.1 || ^22.0.0",
108
+ "@adonisjs/session": "^8.0.0-next.1 || ^8.0.0",
109
109
  "@japa/api-client": "^3.1.1",
110
110
  "@japa/browser-client": "^2.2.0",
111
- "@japa/plugin-adonisjs": "^5.1.0-next.0"
111
+ "@japa/plugin-adonisjs": "^5.1.0-next.0 || ^5.1.0"
112
112
  },
113
113
  "peerDependenciesMeta": {
114
114
  "@adonisjs/assembler": {
@@ -1,129 +0,0 @@
1
- import { n as E_UNAUTHORIZED_ACCESS } from "./errors-Ns_FO2np.js";
2
- import { t as debug_default } from "./debug-Ckko95-M.js";
3
- import { RuntimeException } from "@adonisjs/core/exceptions";
4
- import { HttpContextFactory } from "@adonisjs/core/factories/http";
5
- var Authenticator = class {
6
- #config;
7
- #guardsCache = {};
8
- #authenticationAttemptedViaGuard;
9
- #authenticatedViaGuard;
10
- #ctx;
11
- get defaultGuard() {
12
- return this.#config.default;
13
- }
14
- get authenticatedViaGuard() {
15
- return this.#authenticatedViaGuard;
16
- }
17
- get isAuthenticated() {
18
- if (!this.#authenticationAttemptedViaGuard) return false;
19
- return this.use(this.#authenticationAttemptedViaGuard).isAuthenticated;
20
- }
21
- get user() {
22
- if (!this.#authenticationAttemptedViaGuard) return;
23
- return this.use(this.#authenticationAttemptedViaGuard).user;
24
- }
25
- get authenticationAttempted() {
26
- if (!this.#authenticationAttemptedViaGuard) return false;
27
- return this.use(this.#authenticationAttemptedViaGuard).authenticationAttempted;
28
- }
29
- constructor(ctx, config) {
30
- this.#ctx = ctx;
31
- this.#config = config;
32
- debug_default("creating authenticator. config %O", this.#config);
33
- }
34
- getUserOrFail() {
35
- if (!this.#authenticationAttemptedViaGuard) throw new RuntimeException("Cannot access authenticated user. Please call \"auth.authenticate\" method first.");
36
- return this.use(this.#authenticationAttemptedViaGuard).getUserOrFail();
37
- }
38
- use(guard) {
39
- const guardToUse = guard || this.#config.default;
40
- const cachedGuard = this.#guardsCache[guardToUse];
41
- if (cachedGuard) {
42
- debug_default("authenticator: using guard from cache. name: \"%s\"", guardToUse);
43
- return cachedGuard;
44
- }
45
- const guardFactory = this.#config.guards[guardToUse];
46
- debug_default("authenticator: creating guard. name: \"%s\"", guardToUse);
47
- const guardInstance = guardFactory(this.#ctx);
48
- this.#guardsCache[guardToUse] = guardInstance;
49
- return guardInstance;
50
- }
51
- async authenticate() {
52
- await this.authenticateUsing();
53
- return this.getUserOrFail();
54
- }
55
- async check() {
56
- this.#authenticationAttemptedViaGuard = this.defaultGuard;
57
- const isAuthenticated = await this.use().check();
58
- if (isAuthenticated) this.#authenticatedViaGuard = this.defaultGuard;
59
- return isAuthenticated;
60
- }
61
- async authenticateUsing(guards, options) {
62
- const guardsToUse = guards || [this.defaultGuard];
63
- let lastUsedDriver;
64
- for (let guardName of guardsToUse) {
65
- debug_default("attempting to authenticate using guard \"%s\"", guardName);
66
- this.#authenticationAttemptedViaGuard = guardName;
67
- const guard = this.use(guardName);
68
- lastUsedDriver = guard.driverName;
69
- if (await guard.check()) {
70
- this.#authenticatedViaGuard = guardName;
71
- return this.getUserOrFail();
72
- }
73
- }
74
- throw new E_UNAUTHORIZED_ACCESS("Unauthorized access", {
75
- guardDriverName: lastUsedDriver,
76
- redirectTo: options?.loginRoute
77
- });
78
- }
79
- async checkUsing(guards = [this.defaultGuard]) {
80
- for (const name of guards) {
81
- this.#authenticationAttemptedViaGuard = name;
82
- if (await this.use(name).check()) {
83
- this.#authenticatedViaGuard = name;
84
- return true;
85
- }
86
- }
87
- return false;
88
- }
89
- };
90
- var AuthenticatorClient = class {
91
- #config;
92
- #guardsCache = {};
93
- get defaultGuard() {
94
- return this.#config.default;
95
- }
96
- constructor(config) {
97
- this.#config = config;
98
- debug_default("creating authenticator client. config %O", this.#config);
99
- }
100
- use(guard) {
101
- const guardToUse = guard || this.#config.default;
102
- const cachedGuard = this.#guardsCache[guardToUse];
103
- if (cachedGuard) {
104
- debug_default("authenticator client: using guard from cache. name: \"%s\"", guardToUse);
105
- return cachedGuard;
106
- }
107
- const guardFactory = this.#config.guards[guardToUse];
108
- debug_default("authenticator client: creating guard. name: \"%s\"", guardToUse);
109
- const guardInstance = guardFactory(new HttpContextFactory().create());
110
- this.#guardsCache[guardToUse] = guardInstance;
111
- return guardInstance;
112
- }
113
- };
114
- var AuthManager = class {
115
- get defaultGuard() {
116
- return this.config.default;
117
- }
118
- constructor(config) {
119
- this.config = config;
120
- this.config = config;
121
- }
122
- createAuthenticator(ctx) {
123
- return new Authenticator(ctx, this.config);
124
- }
125
- createAuthenticatorClient() {
126
- return new AuthenticatorClient(this.config);
127
- }
128
- };
129
- export { AuthenticatorClient as n, Authenticator as r, AuthManager as t };
@@ -1,3 +0,0 @@
1
- import { debuglog } from "node:util";
2
- var debug_default = debuglog("adonisjs:auth");
3
- export { debug_default as t };