refactor: 统一认证响应
This commit is contained in:
@@ -29,10 +29,10 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (*types.LoginResp, string, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
if len(req.Username) < 3 || len(req.Password) < 8 || len(req.Password) > 20 {
|
||||
return nil, errors.New("the information is illegal")
|
||||
return nil, "", errors.New("the information is illegal")
|
||||
}
|
||||
|
||||
res, err := l.svcCtx.UserRpc.Login(l.ctx, &usercenter.LoginReq{
|
||||
@@ -42,17 +42,15 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro
|
||||
logx.Infof("res:%v", res)
|
||||
if err != nil {
|
||||
logx.Errorf("rpc login err: %v", err)
|
||||
return nil, errors.New("login fail")
|
||||
return nil, "", errors.New("login fail")
|
||||
}
|
||||
|
||||
if res == nil || res.Id <= 0 || res.Username == "" || res.Token == "" {
|
||||
logx.Errorf("rpc login returned empty payload, username=%s, resp=%+v", req.Username, res)
|
||||
return nil, errors.New("login fail")
|
||||
return nil, "", errors.New("login fail")
|
||||
}
|
||||
|
||||
return &types.LoginResp{
|
||||
AccessToken: "",
|
||||
RefreshToken: res.Token,
|
||||
User: types.User{},
|
||||
}, nil
|
||||
User: types.User{},
|
||||
}, res.Token, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user