123456789101112131415161718192021 |
- package hook
- import (
- "context"
- "errors"
- "wechat-api/ent"
- tokenModel "wechat-api/ent/token"
- )
- // CheckDesktopAuth 检查token是否合法同时返回token实例
- func CheckDesktopAuth(tokenStr string, client *ent.Client) (*ent.Token, error) {
- if tokenStr == "" {
- return nil, errors.New("auth cannot be null")
- }
- token, err := client.Token.Query().Where(tokenModel.Token(tokenStr)).Only(context.Background())
- if err != nil {
- return nil, err
- }
- return token, nil
- }
|