fix: totp login
This commit is contained in:
@@ -244,8 +244,8 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
||||
return nil, err
|
||||
}
|
||||
authenticator, err := db.Provider.GetAuthenticatorDetailsByUserId(ctx, user.ID, constants.EnvKeyTOTPAuthenticator)
|
||||
// Check if it's the first time user or if their TOTP is not verified
|
||||
if err != nil || ((authenticator == nil) || (authenticator != nil && authenticator.VerifiedAt == nil)) {
|
||||
if err != nil || authenticator == nil || authenticator.VerifiedAt == nil {
|
||||
// generate totp
|
||||
// Generate a base64 URL and initiate the registration for TOTP
|
||||
authConfig, err := authenticators.Provider.Generate(ctx, user.ID)
|
||||
if err != nil {
|
||||
|
@@ -58,10 +58,14 @@ func VerifyOtpResolver(ctx context.Context, params model.VerifyOTPRequest) (*mod
|
||||
// Verify OTP based on TOPT or OTP
|
||||
if refs.BoolValue(params.Totp) {
|
||||
status, err := authenticators.Provider.Validate(ctx, params.Otp, user.ID)
|
||||
if err != nil || !status {
|
||||
if err != nil {
|
||||
log.Debug("Failed to validate totp: ", err)
|
||||
return nil, fmt.Errorf("error while validating passcode")
|
||||
}
|
||||
if !status {
|
||||
log.Debug("Failed to verify otp request: Incorrect value")
|
||||
return res, fmt.Errorf(`invalid otp`)
|
||||
}
|
||||
} else {
|
||||
var otp *models.OTP
|
||||
if currentField == models.FieldNameEmail {
|
||||
|
Reference in New Issue
Block a user