Skip to content

Commit

Permalink
fix(mixins): receive a function instead of the hash module directly
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Jan 24, 2024
1 parent 3526488 commit 3c5018c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/mixins/with_auth_finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { E_INVALID_CREDENTIALS } from '../errors.js'
* timing attacks.
*/
export function withAuthFinder(
hash: Hash,
hash: () => Hash,
options: {
uids: string[]
passwordColumnName: string
Expand All @@ -43,7 +43,7 @@ export function withAuthFinder(
user: InstanceType<T>
) {
if (user.$dirty[options.passwordColumnName]) {
;(user as any)[options.passwordColumnName] = await hash.make(
;(user as any)[options.passwordColumnName] = await hash().make(
(user as any)[options.passwordColumnName]
)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ export function withAuthFinder(

const user = await this.findForAuth(options.uids, uid)
if (!user) {
await hash.make(password)
await hash().make(password)
throw new E_INVALID_CREDENTIALS('Invalid user credentials')
}

Expand All @@ -93,7 +93,7 @@ export function withAuthFinder(
)
}

if (await hash.verify(passwordHash, password)) {
if (await hash().verify(passwordHash, password)) {
return user
}

Expand Down
16 changes: 8 additions & 8 deletions tests/auth/mixins/with_auth_finder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.group('withAuthFinder | findForAuth', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -66,7 +66,7 @@ test.group('withAuthFinder | findForAuth', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -104,7 +104,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -141,7 +141,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -173,7 +173,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -211,7 +211,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -249,7 +249,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down Expand Up @@ -300,7 +300,7 @@ test.group('withAuthFinder | verify', () => {

class User extends compose(
BaseModel,
withAuthFinder(hash, {
withAuthFinder(() => hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
Expand Down

0 comments on commit 3c5018c

Please sign in to comment.