Skip to content

Commit d35207f

Browse files
committed
Remove this.init from inside class, call them in the tests instead
1 parent d4ce855 commit d35207f

File tree

3 files changed

+319
-66
lines changed

3 files changed

+319
-66
lines changed

packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts

-15
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ export class DbAuthHandler<
540540
)
541541
}
542542

543-
await this.init()
544-
545543
const { username } = this.normalizedRequest.jsonBody || {}
546544
// was the username sent in at all?
547545
if (!username || username.trim() === '') {
@@ -640,7 +638,6 @@ export class DbAuthHandler<
640638
)
641639
}
642640

643-
await this.init()
644641
const { username, password } = this.normalizedRequest.jsonBody || {}
645642
const dbUser = await this._verifyUser(username, password)
646643
const handlerUser = await (this.options.login as LoginFlowOptions).handler(
@@ -670,7 +667,6 @@ export class DbAuthHandler<
670667
)
671668
}
672669

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

676672
// is the resetToken present?
@@ -743,7 +739,6 @@ export class DbAuthHandler<
743739
`Signup flow is not enabled`
744740
)
745741
}
746-
await this.init()
747742

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

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

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

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

889881
const webAuthnOptions = this.options.webAuthn
890882

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

956947
const webAuthnOptions = this.options.webAuthn
957948

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

1001991
const user = await this._getCurrentUser()
1002992

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

13961385
// gets the user from the database and returns only its ID
13971386
async _getCurrentUser() {
1398-
await this.init()
1399-
14001387
if (!this.session?.id) {
14011388
throw new DbAuthError.NotLoggedInError()
14021389
}
@@ -1431,7 +1418,6 @@ export class DbAuthHandler<
14311418
// creates and returns a user, first checking that the username/password
14321419
// values pass validation
14331420
async _createUser() {
1434-
await this.init()
14351421
const { username, password, ...userAttributes } =
14361422
this.normalizedRequest.jsonBody || {}
14371423
if (
@@ -1469,7 +1455,6 @@ export class DbAuthHandler<
14691455

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

0 commit comments

Comments
 (0)