Skip to content

Commit

Permalink
feature(redwoodjs#7787) - Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ageddesi committed Apr 10, 2023
1 parent 6439049 commit 68ab8cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 9 additions & 10 deletions packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,20 +1287,19 @@ export class DbAuthHandler<
this._validateField('username', username) &&
this._validateField('password', password)
) {

// Each db provider has it owns rules for case insensitive comparison.
// We are checking if you have defined one for your db choice here
// https://www.prisma.io/docs/concepts/components/prisma-client/case-sensitivity
const usernameMatchFlowOption = (this.options.signup as SignupFlowOptions)?.usernameMatch;
const findUniqueUserMatchCriteriaOptions = !usernameMatchFlowOption ?
{ [this.options.authFields.username]: username }
:
{
[this.options.authFields.username]: {
equals: username,
mode: usernameMatchFlowOption
const usernameMatchFlowOption = (this.options.signup as SignupFlowOptions)
?.usernameMatch
const findUniqueUserMatchCriteriaOptions = !usernameMatchFlowOption
? { [this.options.authFields.username]: username }
: {
[this.options.authFields.username]: {
equals: username,
mode: usernameMatchFlowOption,
},
}
}

const user = await this.dbAccessor.findUnique({
where: findUniqueUserMatchCriteriaOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,7 @@ describe('dbAuth', () => {
jest.resetAllMocks()
jest.clearAllMocks()

const defaultMessage = options.signup.errors.usernameTaken
const spy = jest.spyOn(db.user, 'findUnique')
delete options.signup.usernameMatch

Expand All @@ -2373,7 +2374,12 @@ describe('dbAuth', () => {
password: 'password',
})
const dbAuth = new DbAuthHandler(event, context, options)
await dbAuth._createUser().catch((e) => {})
await dbAuth._createUser().catch((e) => {
expect(e).toBeInstanceOf(dbAuthError.DuplicateUsernameError)
expect(e.message).toEqual(
defaultMessage.replace(/\$\{username\}/, dbUser.email)
)
})

expect(spy).toHaveBeenCalled()
return expect(spy).not.toHaveBeenCalledWith({
Expand Down

0 comments on commit 68ab8cc

Please sign in to comment.