feat: add tenant commands

This commit is contained in:
Rogee
2024-12-07 18:48:05 +08:00
parent e15d8d9bb2
commit 8f88929575
25 changed files with 271 additions and 48 deletions

View File

@@ -11,6 +11,10 @@ import (
)
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
if len(c.GetReqHeaders()["Authorization"]) != 0 {
return c.Next()
}
state := c.Query("state")
code := c.Query("code")
@@ -40,13 +44,16 @@ func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
}
var oauthInfo pg.UserOAuth
copier.Copy(&oauthInfo, token)
if err := copier.Copy(&oauthInfo, token); err != nil {
return errors.Wrap(err, "failed to copy oauth info")
}
user, err := f.userSvc.GetOrNew(c.Context(), tenantId, token.Openid, oauthInfo)
if err != nil {
return errors.Wrap(err, "failed to get user")
}
claim := f.jwt.CreateClaims(jwt.BaseClaims{UID: uint64(user.ID)})
claim := f.jwt.CreateClaims(jwt.BaseClaims{OpenID: user.OpenID})
claim.ID = user.OpenID
jwtToken, err := f.jwt.CreateToken(claim)
if err != nil {