mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
20 lines
359 B
Go
20 lines
359 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v3"
|
|
"nysoure/server/model"
|
|
"nysoure/server/utils"
|
|
)
|
|
|
|
func JwtMiddleware(c fiber.Ctx) error {
|
|
token := c.Get("Authorization")
|
|
if token != "" {
|
|
id, err := utils.ParseToken(token)
|
|
if err != nil {
|
|
return model.NewUnAuthorizedError("Invalid token")
|
|
}
|
|
c.Locals("uid", id)
|
|
}
|
|
return c.Next()
|
|
}
|