46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package grpcserver
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
grpcproto "git.coopgo.io/coopgo-apps/silvermobi/servers/grpcapi/proto"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (s SilvermobiGRPCService) AuthLogin(ctx context.Context, req *grpcproto.AuthLoginRequest) (res *grpcproto.AuthLoginResponse, err error) {
|
|
log.Info().
|
|
Str("username", req.Username).
|
|
Msg("AuthLogin")
|
|
|
|
jwt, err := s.Handler.Login(ctx, req.Username, req.Password)
|
|
if err != nil {
|
|
log.Error().
|
|
Err(err).
|
|
Str("username", req.Username).
|
|
Msg("user not found")
|
|
|
|
return nil, errors.New("user/password not found")
|
|
}
|
|
|
|
return &grpcproto.AuthLoginResponse{
|
|
Token: jwt,
|
|
}, nil
|
|
}
|
|
|
|
func (s SilvermobiGRPCService) AuthRegister(ctx context.Context, req *grpcproto.AuthRegisterRequest) (res *grpcproto.AuthRegisterResponse, err error) {
|
|
log.Info().
|
|
Str("username", req.Email).
|
|
Msg("AuthRegister")
|
|
|
|
jwt, err := s.Handler.Register(ctx, req.Email, req.Password, req.Email, req.PhoneNumber, req.FirstName, req.LastName)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("AuthRegister failed")
|
|
return nil, errors.New("could not register user")
|
|
}
|
|
|
|
return &grpcproto.AuthRegisterResponse{
|
|
Token: jwt,
|
|
}, nil
|
|
}
|