feat: add email/password registration#59
Conversation
39b25f2 to
46be641
Compare
46be641 to
ec4d7e3
Compare
| return "", fmt.Errorf("the email has been registerd") | ||
| } | ||
|
|
||
| hashPassword, err := HashPassword(password) |
There was a problem hiding this comment.
Rename hashPassword to hashedPassword
| id, err := queries.CreateAccount(ctx, database.CreateAccountParams{ | ||
| Email: email, | ||
| Password: hashPassword, | ||
| Name: name, | ||
| }) |
There was a problem hiding this comment.
After generate new sqlc add following there I just mention
| panic(err) | ||
| } | ||
|
|
||
| authService := auth.NewAuthService(pool) |
There was a problem hiding this comment.
Move auth service init to internal/http/server
| 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) |
There was a problem hiding this comment.
In here we should need a context timeout here, set the timeout for about 5 secs
| return "", fmt.Errorf("can not create new account") | ||
| } | ||
|
|
||
| return id.String(), nil |
There was a problem hiding this comment.
Drop string and return nil only, nil error mean the func is work as expected
| queries := database.New(s.Pool) | ||
|
|
||
| _, err := queries.GetAccountByEmail(ctx, email) | ||
| if err == nil { |
There was a problem hiding this comment.
Why u use an err to believe that when an error happen during query, 100% is email is existed ?
c4a5700 to
6835546
Compare
6835546 to
536cae0
Compare
536cae0 to
10d78dc
Compare
| ctx, cancel := context.WithTimeout(ctx, defaultTimeout) | ||
| defer cancel() |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
| "github.com/go-playground/validator/v10" | ||
| ) | ||
|
|
||
| func Init() (*validator.Validate, error) { |
#4