Skip to content

feat: add email/password registration#59

Merged
kazetani-SE merged 11 commits into
mainfrom
feat/email-password-register
May 16, 2026
Merged

feat: add email/password registration#59
kazetani-SE merged 11 commits into
mainfrom
feat/email-password-register

Conversation

@kazetani-SE

Copy link
Copy Markdown
Contributor

#4

@kazetani-SE
kazetani-SE requested review from AnataAria and akagiyuu May 8, 2026 07:25
@kazetani-SE
kazetani-SE force-pushed the feat/email-password-register branch from 39b25f2 to 46be641 Compare May 8, 2026 07:33
@kazetani-SE
kazetani-SE force-pushed the feat/email-password-register branch from 46be641 to ec4d7e3 Compare May 8, 2026 07:37
@kazetani-SE kazetani-SE linked an issue May 8, 2026 that may be closed by this pull request
Comment thread internal/auth/password.go Outdated
Comment thread internal/auth/service.go Outdated
return "", fmt.Errorf("the email has been registerd")
}

hashPassword, err := HashPassword(password)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename hashPassword to hashedPassword

Comment thread internal/auth/service.go Outdated
Comment thread internal/auth/service.go Outdated
Comment thread internal/auth/service.go Outdated
Comment thread internal/http/auth.dto.go Outdated
Comment thread internal/http/auth.handler.go Outdated
Comment thread internal/http/auth.handler.go Outdated
Comment thread internal/http/auth.handler.go Outdated
Comment thread internal/http/auth.handler.go Outdated
@akagiyuu
akagiyuu requested a review from patohru May 8, 2026 08:45
Comment thread internal/database/query/account.sql
Comment thread internal/http/auth.dto.go
Comment thread internal/auth/service.go Outdated
Comment on lines +32 to +36
id, err := queries.CreateAccount(ctx, database.CreateAccountParams{
Email: email,
Password: hashPassword,
Name: name,
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After generate new sqlc add following there I just mention

Comment thread cmd/http/main.go
panic(err)
}

authService := auth.NewAuthService(pool)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move auth service init to internal/http/server

Comment thread cmd/http/main.go
Comment thread cmd/http/main.go

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move it to internal/config

Comment thread internal/database/database.go
Comment thread internal/auth/service.go Outdated
func (s *AuthService) Register(ctx context.Context, email string, password string, name string) (string, error) {
queries := database.New(s.Pool)

_, err := queries.GetAccountByEmail(ctx, email)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here we should need a context timeout here, set the timeout for about 5 secs

Comment thread internal/auth/service.go Outdated
return "", fmt.Errorf("can not create new account")
}

return id.String(), nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop string and return nil only, nil error mean the func is work as expected

Comment thread internal/database/query/account.sql Outdated
Comment thread internal/auth/service.go Outdated
queries := database.New(s.Pool)

_, err := queries.GetAccountByEmail(ctx, email)
if err == nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why u use an err to believe that when an error happen during query, 100% is email is existed ?

Comment thread internal/http/auth.handler.go
Comment thread internal/config/config.go Outdated
Comment thread internal/http/auth.handler.go
Comment thread internal/database/query/account.sql Outdated
@kazetani-SE
kazetani-SE force-pushed the feat/email-password-register branch from c4a5700 to 6835546 Compare May 12, 2026 13:46
@kazetani-SE
kazetani-SE requested review from akagiyuu and patohru May 12, 2026 13:48
@kazetani-SE
kazetani-SE force-pushed the feat/email-password-register branch from 6835546 to 536cae0 Compare May 12, 2026 13:59
@kazetani-SE
kazetani-SE force-pushed the feat/email-password-register branch from 536cae0 to 10d78dc Compare May 12, 2026 14:14
Comment thread internal/database/database.go
Comment thread internal/database/database.config.go Outdated
@kazetani-SE
kazetani-SE requested a review from patohru May 13, 2026 13:40
Comment thread internal/database/query/account.sql Outdated
Comment thread internal/http/validation.go
Comment thread internal/http/auth.handler.go
Comment thread internal/http/auth.handler.go Outdated
Comment thread internal/auth/service.go Outdated
Comment on lines +30 to +31
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
defer cancel()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use the ctx in the parameter instead. fuego will automatically handle timeout,... for you (that ctx will have request scope, and live until request end or cancelled)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember fuego handle timeout like that, it handle timeout from net/http like read, write and doesn't have cancel like WithTimeout. But I think he's already use ctx from the params no?

Comment thread internal/auth/service.go Outdated
Comment thread internal/auth/service.go
Comment thread internal/http/auth.handler.go Outdated
Comment thread internal/validation/validation.go Outdated
@kazetani-SE
kazetani-SE requested a review from akagiyuu May 14, 2026 15:15
Comment thread internal/http/validation.go
@kazetani-SE
kazetani-SE requested a review from akagiyuu May 15, 2026 10:06
Comment thread internal/http/validation.go Outdated
"github.com/go-playground/validator/v10"
)

func Init() (*validator.Validate, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to NewValidator

Comment thread internal/http/validation.go
@kazetani-SE
kazetani-SE requested a review from akagiyuu May 15, 2026 14:06
@kazetani-SE
kazetani-SE merged commit 50a5138 into main May 16, 2026
3 checks passed
@kazetani-SE
kazetani-SE deleted the feat/email-password-register branch May 16, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement email/password registration

4 participants