feat: add tenant commands
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"backend/common/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (f *Middlewares) JwtParse(c fiber.Ctx) error {
|
||||
func (f *Middlewares) ParseJWT(c fiber.Ctx) error {
|
||||
tokens := c.GetReqHeaders()["Authorization"]
|
||||
if len(tokens) == 0 {
|
||||
return c.Next()
|
||||
@@ -22,13 +20,20 @@ func (f *Middlewares) JwtParse(c fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// query user
|
||||
user, err := f.userSvc.GetByOpenID(c.Context(), claim.ID)
|
||||
user, err := f.userSvc.GetByOpenID(c.Context(), claim.OpenID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get user")
|
||||
}
|
||||
claim.UserID = user.ID
|
||||
|
||||
c.SetUserContext(context.WithValue(c.UserContext(), consts.CtxKeyJwt, token))
|
||||
c.SetUserContext(context.WithValue(c.UserContext(), consts.CtxKeySession, user))
|
||||
tenantId, err := f.userSvc.GetTenantIDBySlug(c.Context(), claim.Tenant)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get tenant")
|
||||
}
|
||||
claim.TenantID = tenantId
|
||||
|
||||
c.Locals(consts.CtxKeyJwt, token)
|
||||
c.Locals(consts.CtxKeyClaim, claim)
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user