6 files changed,
25 insertions(+),
4 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2024-09-15 09:06:12 +0300
Parent:
1c67ba5
M
.env.example
@@ -1,4 +1,5 @@
APP_ENV=debug +APP_URL=http://localhost:3000 SERVER_PORT=3000 PASSWORD_SALT=onasty
M
cmd/server/main.go
@@ -69,6 +69,7 @@ jwtTokenizer,
mailGunMailer, cfg.JwtRefreshTokenTTL, cfg.VerficationTokenTTL, + cfg.AppURL, ) noterepo := noterepo.New(psqlDB)
M
e2e/e2e_test.go
@@ -106,6 +106,7 @@ e.jwtTokenizer,
e.mailer, cfg.JwtRefreshTokenTTL, cfg.VerficationTokenTTL, + cfg.AppURL, ) noterepo := noterepo.New(e.postgresDB)@@ -177,6 +178,7 @@
func (e *AppTestSuite) getConfig() *config.Config { return &config.Config{ //nolint:exhaustruct AppEnv: "testing", + AppURL: "", ServerPort: "3000", PasswordSalt: "salty-password", JwtSigningKey: "jwt-key",
M
internal/config/config.go
@@ -8,6 +8,7 @@ )
type Config struct { AppEnv string + AppURL string ServerPort string PostgresDSN string PasswordSalt string@@ -29,6 +30,7 @@
func NewConfig() *Config { return &Config{ AppEnv: getenvOrDefault("APP_ENV", "debug"), + AppURL: getenvOrDefault("APP_URL", ""), ServerPort: getenvOrDefault("SERVER_PORT", "3000"), PostgresDSN: getenvOrDefault("POSTGRESQL_DSN", ""), PasswordSalt: getenvOrDefault("PASSWORD_SALT", ""),
M
internal/service/usersrv/email.go
@@ -23,6 +23,7 @@ ctx context.Context,
cancel context.CancelFunc, userEmail string, token string, + url string, ) error { select { case <-ctx.Done():@@ -33,8 +34,7 @@ if err := u.mailer.Send(
ctx, userEmail, verificationEmailSubject, - // TODO: set proper url - fmt.Sprintf(verificationEmailBody, "http://localhost:3000", token), + fmt.Sprintf(verificationEmailBody, url, token), ); err != nil { return errors.Join(ErrFailedToSendVerifcationEmail, err) }
M
internal/service/usersrv/usersrv.go
@@ -45,6 +45,7 @@ mailer mailer.Mailer
refreshTokenTTL time.Duration verificationTokenTTL time.Duration + appURL string } func New(@@ -55,6 +56,7 @@ hasher hasher.Hasher,
jwtTokenizer jwtutil.JWTTokenizer, mailer mailer.Mailer, refreshTokenTTL, verificationTokenTTL time.Duration, + appURL string, ) *UserSrv { return &UserSrv{ userstore: userstore,@@ -65,6 +67,7 @@ jwtTokenizer: jwtTokenizer,
mailer: mailer, refreshTokenTTL: refreshTokenTTL, verificationTokenTTL: verificationTokenTTL, + appURL: appURL, } }@@ -93,7 +96,13 @@
// TODO: handle the error that might be returned // i dont think that tehre's need to handle the error, just log it bgCtx, bgCancel := context.WithTimeout(context.Background(), 10*time.Second) - go u.sendVerificationEmail(bgCtx, bgCancel, inp.Email, vtok) //nolint:errcheck,contextcheck + go u.sendVerificationEmail( //nolint:errcheck,contextcheck + bgCtx, + bgCancel, + inp.Email, + vtok, + u.appURL, + ) return uid, nil }@@ -211,7 +220,13 @@ return err
} bgCtx, bgCancel := context.WithTimeout(context.Background(), 10*time.Second) - go u.sendVerificationEmail(bgCtx, bgCancel, inp.Email, token) //nolint:errcheck,contextcheck + go u.sendVerificationEmail( //nolint:errcheck,contextcheck + bgCtx, + bgCancel, + inp.Email, + token, + u.appURL, + ) return nil }