@adonisjs/auth 10.0.0-next.1 → 10.0.0-next.2

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,4 +1,4 @@
1
- import type { Hash } from '@adonisjs/core/hash';
1
+ import type { Hash, HashManager } from '@adonisjs/core/hash';
2
2
  import { type BaseModel } from '@adonisjs/lucid/orm';
3
3
  import type { NormalizeConstructor } from '@adonisjs/core/types/helpers';
4
4
  type UserWithUserFinderRow = {
@@ -34,8 +34,8 @@ type UserWithUserFinderClass<Model extends NormalizeConstructor<typeof BaseModel
34
34
  * // User model implementation
35
35
  * }
36
36
  */
37
- export declare function withAuthFinder(hash: () => Hash, options: {
38
- uids: string[];
39
- passwordColumnName: string;
37
+ export declare function withAuthFinder(hash: (() => Hash) | HashManager<any>, options?: {
38
+ uids?: string[];
39
+ passwordColumnName?: string;
40
40
  }): <Model extends NormalizeConstructor<typeof BaseModel>>(superclass: Model) => UserWithUserFinderClass<Model>;
41
41
  export {};
@@ -9,13 +9,15 @@ import {
9
9
  import { RuntimeException } from "@adonisjs/core/exceptions";
10
10
  import { beforeSave } from "@adonisjs/lucid/orm";
11
11
  function withAuthFinder(hash, options) {
12
+ let normalizedOptions = { uids: ["email"], passwordColumnName: "password", ...options };
13
+ let hashFactory = typeof hash === "function" ? hash : () => hash.use();
12
14
  return function(superclass) {
13
15
  class UserWithUserFinder extends superclass {
14
16
  static async hashPassword(user) {
15
- if (user.$dirty[options.passwordColumnName]) {
17
+ if (user.$dirty[normalizedOptions.passwordColumnName]) {
16
18
  ;
17
- user[options.passwordColumnName] = await hash().make(
18
- user[options.passwordColumnName]
19
+ user[normalizedOptions.passwordColumnName] = await hashFactory().make(
20
+ user[normalizedOptions.passwordColumnName]
19
21
  );
20
22
  }
21
23
  }
@@ -52,9 +54,9 @@ function withAuthFinder(hash, options) {
52
54
  if (!uid || !password) {
53
55
  throw new E_INVALID_CREDENTIALS("Invalid user credentials");
54
56
  }
55
- const user = await this.findForAuth(options.uids, uid);
57
+ const user = await this.findForAuth(normalizedOptions.uids, uid);
56
58
  if (!user) {
57
- await hash().make(password);
59
+ await hashFactory().make(password);
58
60
  throw new E_INVALID_CREDENTIALS("Invalid user credentials");
59
61
  }
60
62
  if (await user.verifyPassword(password)) {
@@ -77,13 +79,13 @@ function withAuthFinder(hash, options) {
77
79
  * }
78
80
  */
79
81
  verifyPassword(plainPassword) {
80
- const passwordHash = this[options.passwordColumnName];
82
+ const passwordHash = this[normalizedOptions.passwordColumnName];
81
83
  if (!passwordHash) {
82
84
  throw new RuntimeException(
83
- `Cannot verify password. The value for "${options.passwordColumnName}" column is undefined or null`
85
+ `Cannot verify password. The value for "${normalizedOptions.passwordColumnName}" column is undefined or null`
84
86
  );
85
87
  }
86
- return hash().verify(passwordHash, plainPassword);
88
+ return hashFactory().verify(passwordHash, plainPassword);
87
89
  }
88
90
  }
89
91
  __decorateClass([
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.1",
4
+ "version": "10.0.0-next.2",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -51,8 +51,8 @@
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.9",
55
- "@adonisjs/core": "^7.0.0-next.7",
54
+ "@adonisjs/assembler": "^8.0.0-next.14",
55
+ "@adonisjs/core": "^7.0.0-next.8",
56
56
  "@adonisjs/eslint-config": "^3.0.0-next.1",
57
57
  "@adonisjs/i18n": "^3.0.0-next.1",
58
58
  "@adonisjs/lucid": "^22.0.0-next.1",
@@ -71,7 +71,7 @@
71
71
  "@release-it/conventional-changelog": "^10.0.1",
72
72
  "@types/basic-auth": "^1.1.8",
73
73
  "@types/luxon": "^3.7.1",
74
- "@types/node": "^24.8.1",
74
+ "@types/node": "^24.9.1",
75
75
  "@types/set-cookie-parser": "^2.4.10",
76
76
  "@types/sinon": "^17.0.4",
77
77
  "c8": "^10.1.3",
@@ -82,7 +82,7 @@
82
82
  "dotenv": "^17.2.3",
83
83
  "eslint": "^9.38.0",
84
84
  "luxon": "^3.7.2",
85
- "mysql2": "^3.15.2",
85
+ "mysql2": "^3.15.3",
86
86
  "nock": "^14.0.10",
87
87
  "pg": "^8.16.3",
88
88
  "playwright": "^1.56.1",