feat: update auth middlewares
This commit is contained in:
@@ -19,12 +19,14 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
user, err := models.Users.GetByID(ctx.Context(), 1)
|
||||
if err != nil {
|
||||
return ctx.Send([]byte("User not found"))
|
||||
if f.app.IsDevMode() {
|
||||
user, err := models.Users.GetByID(ctx.Context(), 1)
|
||||
if err != nil {
|
||||
return ctx.Send([]byte("User not found"))
|
||||
}
|
||||
ctx.Locals("user", user)
|
||||
return ctx.Next()
|
||||
}
|
||||
ctx.Locals("user", user)
|
||||
return ctx.Next()
|
||||
|
||||
fullUrl := string(ctx.Request().URI().FullURI())
|
||||
u, err := url.Parse(fullUrl)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"quyun/providers/app"
|
||||
"quyun/providers/jwt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
type Middlewares struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
jwt *jwt.JWT
|
||||
app *app.Config
|
||||
}
|
||||
|
||||
func (f *Middlewares) Prepare() error {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"quyun/providers/app"
|
||||
"quyun/providers/jwt"
|
||||
|
||||
"go.ipao.vip/atom/container"
|
||||
@@ -9,9 +10,11 @@ import (
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func(
|
||||
app *app.Config,
|
||||
jwt *jwt.JWT,
|
||||
) (*Middlewares, error) {
|
||||
obj := &Middlewares{
|
||||
app: app,
|
||||
jwt: jwt,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user