| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // Code scaffolded by goctl. Safe to edit.
- // goctl 1.10.0
- package auth
- import (
- "context"
- "perms-system-server/internal/middleware"
- "perms-system-server/internal/response"
- "perms-system-server/internal/svc"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type LogoutLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
- return &LogoutLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *LogoutLogic) Logout() error {
- userId := middleware.GetUserId(l.ctx)
- if userId == 0 {
- return response.ErrUnauthorized("未登录")
- }
- if _, err := l.svcCtx.SysUserModel.IncrementTokenVersion(l.ctx, userId); err != nil {
- return err
- }
- l.svcCtx.UserDetailsLoader.Clean(l.ctx, userId)
- return nil
- }
|