diff --git a/internal/app/httpserver/user/register.go b/internal/app/httpserver/user/register.go index d0a2355..516d461 100644 --- a/internal/app/httpserver/user/register.go +++ b/internal/app/httpserver/user/register.go @@ -33,7 +33,7 @@ func (r *userRouter) Register(ctx *gin.Context) { return } - err := r.authUseCase.Register(ctx, req.Login, req.Password) + userID, err := r.authUseCase.Register(ctx, req.Login, req.Password) if err != nil && errors.As(err, &autherrors.UserAlreadyExistsError{}) { ctx.AbortWithStatus(http.StatusConflict) @@ -46,7 +46,7 @@ func (r *userRouter) Register(ctx *gin.Context) { return } - err = r.authorizeUser(ctx, req.Login) + err = r.authorizeUser(ctx, userID) if err != nil { r.logger.ErrorCtx(ctx, fmt.Errorf("failed authorize user")) diff --git a/internal/app/usecase/auth/register.go b/internal/app/usecase/auth/register.go index 5e620f7..764e16c 100644 --- a/internal/app/usecase/auth/register.go +++ b/internal/app/usecase/auth/register.go @@ -7,13 +7,13 @@ import ( "github.com/Froctnow/yandex-go-diploma/internal/app/usecase/auth/errors" ) -func (u *authUseCase) Register(ctx context.Context, login string, password string) error { +func (u *authUseCase) Register(ctx context.Context, login string, password string) (string, error) { hashPassword, err := u.hashPassword(password) if err != nil { err = fmt.Errorf("can't hash password: %w", err) u.logger.ErrorCtx(ctx, err) - return err + return "", err } userID, err := u.provider.CreateUser(ctx, nil, login, hashPassword) @@ -21,14 +21,14 @@ func (u *authUseCase) Register(ctx context.Context, login string, password strin if err != nil { err = fmt.Errorf("can't create user: %w", err) u.logger.ErrorCtx(ctx, err) - return err + return "", err } if userID == "" { err = errors.UserAlreadyExistsError{} u.logger.ErrorCtx(ctx, err) - return err + return "", err } - return nil + return userID, nil } diff --git a/internal/app/usecase/auth/usecase.go b/internal/app/usecase/auth/usecase.go index b0a1969..5bd267b 100644 --- a/internal/app/usecase/auth/usecase.go +++ b/internal/app/usecase/auth/usecase.go @@ -25,7 +25,7 @@ func NewUseCase( } type UseCase interface { - Register(ctx context.Context, login string, password string) error + Register(ctx context.Context, login string, password string) (string, error) Login(ctx context.Context, login string, password string) (string, error) }