Skip to content

Commit

Permalink
Revert "fix(): Added userInsensitive for comparrison checks in dbAuth"
Browse files Browse the repository at this point in the history
This reverts commit 9ad34c7.
  • Loading branch information
ageddesi committed Apr 5, 2023
1 parent eb381da commit 504110d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
12 changes: 3 additions & 9 deletions packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export interface DbAuthHandlerOptions<TUser = Record<string | number, any>> {
authFields: {
id: string
username: string
usernameInsensitive: string
hashedPassword: string
salt: string
resetToken: string
Expand Down Expand Up @@ -217,7 +216,6 @@ export interface DbAuthHandlerOptions<TUser = Record<string | number, any>> {

interface SignupHandlerOptions {
username: string
usernameInsensitive: string
hashedPassword: string
salt: string
userAttributes?: Record<string, string>
Expand Down Expand Up @@ -470,7 +468,7 @@ export class DbAuthHandler<

try {
user = await this.dbAccessor.findUnique({
where: { [this.options.authFields.usernameInsensitive]: username.toLowerCase() },
where: { [this.options.authFields.username]: username },
})
} catch (e) {
throw new DbAuthError.GenericError()
Expand Down Expand Up @@ -1215,7 +1213,7 @@ export class DbAuthHandler<
try {
// does user exist?
user = await this.dbAccessor.findUnique({
where: { [this.options.authFields.usernameInsensitive]: username.toLowerCase() },
where: { [this.options.authFields.username]: username },
})
} catch (e) {
throw new DbAuthError.GenericError()
Expand Down Expand Up @@ -1284,9 +1282,8 @@ export class DbAuthHandler<
this._validateField('username', username) &&
this._validateField('password', password)
) {
const usernameInsensitive = username.toLowerCase()
const user = await this.dbAccessor.findUnique({
where: { [this.options.authFields.usernameInsensitive]: usernameInsensitive },
where: { [this.options.authFields.username]: username },
})
if (user) {
throw new DbAuthError.DuplicateUsernameError(
Expand All @@ -1297,12 +1294,9 @@ export class DbAuthHandler<

// if we get here everything is good, call the app's signup handler and let
// them worry about scrubbing data and saving to the DB
// We are storing both a username and usernameInsenitive so that we retain the pretty formatted version
// the user is expecting to see but use the usernameInsensitive for comparrison checking.
const [hashedPassword, salt] = hashPassword(password)
const newUser = await (this.options.signup as SignupFlowOptions).handler({
username,
usernameInsensitive,
hashedPassword,
salt,
userAttributes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import CryptoJS from 'crypto-js'
import { M } from 'msw/lib/glossary-de6278a9'

import { DbAuthHandler } from '../DbAuthHandler'
import * as dbAuthError from '../errors'
Expand Down Expand Up @@ -84,11 +83,9 @@ const UTC_DATE_REGEX = /\w{3}, \d{2} \w{3} \d{4} [\d:]{8} GMT/
const LOGOUT_COOKIE = 'session=;Expires=Thu, 01 Jan 1970 00:00:00 GMT'

const createDbUser = async (attributes = {}) => {
const email = "roB@redWoodjs.com";
return await db.user.create({
data: {
email,
emailInsensitive: email.toLocaleLowerCase(),
email: 'rob@redwoodjs.com',
hashedPassword:
'0c2b24e20ee76a887eac1415cc2c175ff961e7a0f057cead74789c43399dd5ba',
salt: '2ef27f4073c603ba8b7807c6de6d6a89',
Expand Down Expand Up @@ -132,7 +129,6 @@ describe('dbAuth', () => {
authFields: {
id: 'id',
username: 'email',
usernameInsensitive: 'emailInsensitive',
hashedPassword: 'hashedPassword',
salt: 'salt',
resetToken: 'resetToken',
Expand Down Expand Up @@ -163,7 +159,6 @@ describe('dbAuth', () => {
return db.user.create({
data: {
email: username,
emailInsensitive: username.toLowerCase(),
hashedPassword: hashedPassword,
salt: salt,
name: userAttributes.name,
Expand Down

0 comments on commit 504110d

Please sign in to comment.