fix: forgot password redirect from app

This commit is contained in:
Lakhan Samani
2022-10-24 11:37:42 +05:30
parent e690066652
commit 287b952dad
3 changed files with 22 additions and 19 deletions

View File

@@ -62,11 +62,25 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
log.Debug("Failed to generate nonce: ", err)
return res, err
}
redirectURI := parsers.GetAppURL(gc)
redirectURI := ""
// give higher preference to params redirect uri
if strings.TrimSpace(refs.StringValue(params.RedirectURI)) != "" {
fmt.Println("=> redirect uri from here1", redirectURI)
redirectURI = refs.StringValue(params.RedirectURI)
} else {
redirectURI, err = memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyResetPasswordURL)
fmt.Println("=> redirect uri from here2", redirectURI)
if err != nil {
log.Debug("ResetPasswordURL not found using default app url: ", err)
redirectURI = hostname + "/app/reset-password"
fmt.Println("=> redirect uri from here3", redirectURI)
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyResetPasswordURL, redirectURI)
}
}
fmt.Println("=> redirect uri", redirectURI)
verificationToken, err := token.CreateVerificationToken(params.Email, constants.VerificationTypeForgotPassword, hostname, nonceHash, redirectURI)
if err != nil {
log.Debug("Failed to create verification token", err)
@@ -89,7 +103,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
go email.SendEmail([]string{params.Email}, constants.VerificationTypeForgotPassword, map[string]interface{}{
"user": user.ToMap(),
"organization": utils.GetOrganization(),
"verification_url": utils.GetForgotPasswordURL(verificationToken, hostname, redirectURI),
"verification_url": utils.GetForgotPasswordURL(verificationToken, redirectURI),
})
res = &model.Response{