Skip to content

Commit

Permalink
fix: throw error when uid or password is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 22, 2024
1 parent d92068f commit 8950749
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/mixins/with_auth_finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export function withAuthFinder(
uid: string,
password: string
) {
/**
* Fail when uid or the password are missing
*/
if (!uid || !password) {
throw new E_INVALID_CREDENTIALS('Invalid user credentials')
}

const user = await this.findForAuth(options.uids, uid)
if (!user) {
await hash.make(password)
Expand Down
32 changes: 32 additions & 0 deletions tests/auth/mixins/with_auth_finder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,36 @@ test.group('withAuthFinder | verify', () => {
assert.isBelow(Math.abs(invalidPasswordTime.seconds - invalidEmailTime.seconds), 1)
assert.isBelow(Math.abs(invalidPasswordTime.milliseconds - invalidEmailTime.milliseconds), 10)
})

test('throw error when uid or password values are missing', async ({ assert }) => {
const db = await createDatabase()
await createTables(db)

const hash = getHasher()

class User extends compose(
BaseModel,
withAuthFinder(hash, {
uids: ['email', 'username'],
passwordColumnName: 'password',
})
) {
@column({ isPrimary: true })
declare id: number

@column()
declare username: string

@column()
declare email: string

@column()
declare password: string
}

await assert.rejects(
() => User.verifyCredentials('[email protected]', ''),
'Invalid user credentials'
)
})
})

0 comments on commit 8950749

Please sign in to comment.