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