Browse Source

fix(otp): crash after TOTP enroll

Hintay 4 months ago
parent
commit
a91fe4b5ac
1 changed files with 2 additions and 8 deletions
  1. 2 8
      api/user/otp.go

+ 2 - 8
api/user/otp.go

@@ -1,7 +1,6 @@
 package user
 
 import (
-	"encoding/json"
 	"fmt"
 	"net/http"
 	"strings"
@@ -89,13 +88,8 @@ func EnrollTOTP(c *gin.Context) {
 
 	t := time.Now().Unix()
 	recoveryCodes := model.RecoveryCodes{Codes: generateRecoveryCodes(16), LastViewed: &t}
-	codesJson, err := json.Marshal(&recoveryCodes)
-	if err != nil {
-		api.ErrHandler(c, err)
-		return
-	}
-
-	_, err = u.Where(u.ID.Eq(cUser.ID)).Update(u.RecoveryCodes, codesJson)
+	cUser.RecoveryCodes = recoveryCodes
+	_, err = u.Where(u.ID.Eq(cUser.ID)).Updates(cUser)
 	if err != nil {
 		api.ErrHandler(c, err)
 		return