Skip to content

Commit

Permalink
chore(otp): fix htmx loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed May 7, 2024
1 parent 0e9bd33 commit 7e7a04f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 16 additions & 4 deletions handlers/apis/email_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,39 @@ func (e *emailLoginApi) HandleEmailSignup(w http.ResponseWriter, r *http.Request
func (e *emailLoginApi) HandleEmailOTPVerification(w http.ResponseWriter, r *http.Request) {
verificationToken, err := r.Cookie(handlers.VerificationTokenKey)
if err != nil {
w.Write([]byte("Invalid verification token"))
// w.Write([]byte("Invalid verification token"))
status.
GenericError("Invalid verification token").
Render(context.Background(), w)
return
}
if verificationToken.Expires.After(time.Now().UTC()) {
w.Write([]byte("Expired verification token"))
// w.Write([]byte("Expired verification token"))
status.
GenericError("Expired verification token").
Render(context.Background(), w)
return
}

var reqBody entities.OtpRequest
err = json.NewDecoder(r.Body).Decode(&reqBody)
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusBadRequest)
// w.WriteHeader(http.StatusBadRequest)
status.
GenericError("Invalid verification token").
Render(context.Background(), w)
return
}

sessionToken, err := e.service.VerifyOtp(verificationToken.Value, reqBody)
// TODO: specify errors further suka
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusInternalServerError)
// w.WriteHeader(http.StatusInternalServerError)
status.
GenericError("Something went wrong...").
Render(context.Background(), w)
return
}

Expand Down
3 changes: 3 additions & 0 deletions views/components/otp/otp.templ
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ templ VerifyOtp() {
class={ "flex", "flex-col", "gap-y-[15px]", "lg:gap-y-[35px]" }
hx-post="/api/verify-otp"
hx-ext="json-enc"
hx-target="#replaceable-login-form"
data-loading-target="#loading"
data-loading-class-remove="hidden"
>
<div class={ "flex", "flex-col", "gap-y-[10px]" }>
<label class={ "text-white", "text-[16px]" } for="otp">One Time Password</label>
Expand Down

0 comments on commit 7e7a04f

Please sign in to comment.