add: user auth accomplished

This commit is contained in:
wwweww
2026-02-26 02:17:07 +08:00
parent 300058ad01
commit 60b6f40f9f
54 changed files with 1601 additions and 2303 deletions
@@ -2,6 +2,7 @@ package logic
import (
"context"
"fmt"
"juwan-backend/app/users/rpc/internal/svc"
"juwan-backend/app/users/rpc/pb"
@@ -9,6 +10,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
var USER_TOKEN_TEMP = "jwt:%v"
type ValidateTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
@@ -24,7 +27,20 @@ func NewValidateTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Val
}
func (l *ValidateTokenLogic) ValidateToken(in *pb.ValidateTokenReq) (*pb.ValidateTokenResp, error) {
// todo: add your logic here and delete this line
redisKey := fmt.Sprintf(USER_TOKEN_TEMP, in.UserId)
_, err := l.svcCtx.JwtManager.Valid(l.ctx, redisKey)
if err != nil {
return nil, err
}
users, err := l.svcCtx.UsersModelRO.FindOne(l.ctx, in.UserId)
if err != nil {
return nil, err
}
return &pb.ValidateTokenResp{}, nil
return &pb.ValidateTokenResp{
Valid: true,
Message: "OK",
UserId: in.UserId,
RoleType: users.RoleType,
}, nil
}