Skip to content

Commit

Permalink
Remove this.init from inside class, call them in the tests instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Jan 23, 2024
1 parent d4ce855 commit d35207f
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 66 deletions.
15 changes: 0 additions & 15 deletions packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ export class DbAuthHandler<
)
}

await this.init()

const { username } = this.normalizedRequest.jsonBody || {}
// was the username sent in at all?
if (!username || username.trim() === '') {
Expand Down Expand Up @@ -640,7 +638,6 @@ export class DbAuthHandler<
)
}

await this.init()
const { username, password } = this.normalizedRequest.jsonBody || {}
const dbUser = await this._verifyUser(username, password)
const handlerUser = await (this.options.login as LoginFlowOptions).handler(
Expand Down Expand Up @@ -670,7 +667,6 @@ export class DbAuthHandler<
)
}

await this.init()
const { password, resetToken } = this.normalizedRequest.jsonBody || {}

// is the resetToken present?
Expand Down Expand Up @@ -743,7 +739,6 @@ export class DbAuthHandler<
`Signup flow is not enabled`
)
}
await this.init()

// check if password is valid
const { password } = this.normalizedRequest.jsonBody || {}
Expand All @@ -766,7 +761,6 @@ export class DbAuthHandler<
}

async validateResetToken() {
await this.init()
const { resetToken } = this.normalizedRequest.jsonBody || {}
// is token present at all?
if (!resetToken || String(resetToken).trim() === '') {
Expand All @@ -791,7 +785,6 @@ export class DbAuthHandler<
async webAuthnAuthenticate() {
const { verifyAuthenticationResponse } = require('@simplewebauthn/server')
const webAuthnOptions = this.options.webAuthn
await this.init()

const { rawId } = this.normalizedRequest.jsonBody || {}

Expand Down Expand Up @@ -884,7 +877,6 @@ export class DbAuthHandler<
if (this.options.webAuthn === undefined || !this.options.webAuthn.enabled) {
throw new DbAuthError.WebAuthnError('WebAuthn is not enabled')
}
await this.init()

const webAuthnOptions = this.options.webAuthn

Expand Down Expand Up @@ -951,7 +943,6 @@ export class DbAuthHandler<
if (!this.options?.webAuthn?.enabled) {
throw new DbAuthError.WebAuthnError('WebAuthn is not enabled')
}
await this.init()

const webAuthnOptions = this.options.webAuthn

Expand Down Expand Up @@ -996,7 +987,6 @@ export class DbAuthHandler<
if (this.options.webAuthn === undefined || !this.options.webAuthn.enabled) {
throw new DbAuthError.WebAuthnError('WebAuthn is not enabled')
}
await this.init()

const user = await this._getCurrentUser()

Expand Down Expand Up @@ -1237,7 +1227,6 @@ export class DbAuthHandler<
// checks the CSRF token in the header against the CSRF token in the session
// and throw an error if they are not the same (not used yet)
async _validateCsrf() {
await this.init()
if (
this.sessionCsrfToken !== this.normalizedRequest.headers.get('csrf-token')
) {
Expand Down Expand Up @@ -1395,8 +1384,6 @@ export class DbAuthHandler<

// gets the user from the database and returns only its ID
async _getCurrentUser() {
await this.init()

if (!this.session?.id) {
throw new DbAuthError.NotLoggedInError()
}
Expand Down Expand Up @@ -1431,7 +1418,6 @@ export class DbAuthHandler<
// creates and returns a user, first checking that the username/password
// values pass validation
async _createUser() {
await this.init()
const { username, password, ...userAttributes } =
this.normalizedRequest.jsonBody || {}
if (
Expand Down Expand Up @@ -1469,7 +1455,6 @@ export class DbAuthHandler<

// figure out which auth method we're trying to call
async _getAuthMethod() {
await this.init()
// try getting it from the query string, /.redwood/functions/auth?method=[methodName]
let methodName = this.normalizedRequest.query.method as AuthMethodNames

Expand Down
Loading

0 comments on commit d35207f

Please sign in to comment.