Skip to content

Commit

Permalink
feat(account): frontend domain config for email
Browse files Browse the repository at this point in the history
  • Loading branch information
tithanayut committed Feb 15, 2025
1 parent 14e683d commit 53e8a36
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
10 changes: 9 additions & 1 deletion account/server/core/service/register_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"net/url"

"github.com/lucsky/cuid"
"github.com/pkg/errors"
Expand Down Expand Up @@ -77,10 +78,17 @@ func (s *Service) RegisterAccount(ctx context.Context, traceID, email, name, pas
}
}

verificationURL, err := url.JoinPath(s.config.FrontendBaseUrl, "verify-email", token)
if err != nil {
l.Error().Err(err).Msg("[Service.RegisterAccount] failed to join verification URL")

return errors.Wrap(err, "failed to join verification URL")
}

var body bytes.Buffer
if err = emailVerificationTemplate.Execute(&body, EmailVerificationTemplateData{
Name: name,
VerificationURL: "https://noah.example.com/verify/" + token,
VerificationURL: verificationURL,
}); err != nil {
l.Error().Err(err).Msg("[Service.RegisterAccount] failed to execute email verification template")

Expand Down
10 changes: 9 additions & 1 deletion account/server/core/service/request_password_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"bytes"
"context"
"net/url"
"time"

"github.com/noah-platform/noah/account/server/core"
Expand Down Expand Up @@ -48,10 +49,17 @@ func (s *Service) RequestPasswordReset(ctx context.Context, traceID, email strin
return errors.Wrap(err, "failed to create password reset token")
}

passwordResetURL, err := url.JoinPath(s.config.FrontendBaseUrl, "forget-password", token)
if err != nil {
l.Error().Err(err).Msg("[Service.RegisterAccount] failed to join password reset URL")

return errors.Wrap(err, "failed to join password reset URL")
}

var body bytes.Buffer
if err = emailPasswordResetTemplate.Execute(&body, EmailPasswordResetTemplateData{
Name: account.Name,
PasswordResetURL: "https://noah.example.com/reset-password/" + token,
PasswordResetURL: passwordResetURL,
}); err != nil {
l.Error().Err(err).Msg("[Service.RegisterAccount] failed to execute email password reset template")

Expand Down
3 changes: 2 additions & 1 deletion account/server/core/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type Service struct {
}

type Config struct {
EmailFrom string
EmailFrom string
FrontendBaseUrl string
}

type Dependencies struct {
Expand Down
12 changes: 7 additions & 5 deletions account/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
type Config struct {
Environment string `env:"APP_ENV,required"`

Port string `env:"PORT,required"`
JWTSecret string `env:"JWT_SECRET,required"`
DatabaseUrl string `env:"DATABASE_URL,required"`
KafkaBrokers []string `env:"KAFKA_BROKERS,required"`
Port string `env:"PORT,required"`
JWTSecret string `env:"JWT_SECRET,required"`
DatabaseUrl string `env:"DATABASE_URL,required"`
KafkaBrokers []string `env:"KAFKA_BROKERS,required"`
FrontendBaseUrl string `env:"FRONTEND_BASE_URL,required"`

EmailFrom string `env:"EMAIL_FROM,required"`
EmailKafkaTopic string `env:"EMAIL_KAFKA_TOPIC,required"`
Expand All @@ -38,7 +39,8 @@ func main() {
JWTSecret: cfg.JWTSecret,
},
ServiceConfig: di.ServiceConfig{
EmailFrom: cfg.EmailFrom,
EmailFrom: cfg.EmailFrom,
FrontendBaseUrl: cfg.FrontendBaseUrl,
},
PostgresConfig: di.PostgresConfig{
DatabaseUrl: cfg.DatabaseUrl,
Expand Down

0 comments on commit 53e8a36

Please sign in to comment.