[draft] Move sms verificaiton to otp models

This commit is contained in:
Lakhan Samani
2023-07-12 11:24:13 +05:30
parent 07f71e883b
commit abe809ca68
9 changed files with 78 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ package mongodb
import (
"context"
"errors"
"time"
"github.com/authorizerdev/authorizer/server/db/models"
@@ -12,6 +13,18 @@ import (
// UpsertOTP to add or update otp
func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models.OTP, error) {
// check if email or phone number is present
if otpParam.Email == "" && otpParam.PhoneNumber == "" {
return nil, errors.New("email or phone_number is required")
}
// check if email or phone number is present
if otpParam.Email == "" && otpParam.PhoneNumber == "" {
return nil, errors.New("email or phone_number is required")
}
uniqueField := models.FieldNameEmail
if otp.Email == "" && otp.PhoneNumber != "" {
uniqueField = models.FieldNamePhoneNumber
}
otp, _ := p.GetOTPByEmail(ctx, otpParam.Email)
shouldCreate := false
if otp == nil {