🐛 Fix auth context middleware force provide token

This commit is contained in:
LittleSheep 2024-10-27 00:14:42 +08:00
parent 421834ae5c
commit 999cc2bcd8
3 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,10 @@ import (
func ContextMiddleware(c *fiber.Ctx) error { func ContextMiddleware(c *fiber.Ctx) error {
atk := tokenExtract(c) atk := tokenExtract(c)
if len(atk) == 0 {
return c.Next()
}
c.Locals("nex_in_token", atk) c.Locals("nex_in_token", atk)
if claims, err := tokenRead(atk); err == nil && claims != nil { if claims, err := tokenRead(atk); err == nil && claims != nil {

View File

@ -8,8 +8,6 @@ import (
) )
func MapAPIs(app *fiber.App) { func MapAPIs(app *fiber.App) {
app.Use(auth.ContextMiddleware)
// Some built-in public-accessible APIs // Some built-in public-accessible APIs
wellKnown := app.Group("/.well-known").Name("Well Known") wellKnown := app.Group("/.well-known").Name("Well Known")
{ {

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/internal/auth"
"git.solsynth.dev/hypernet/nexus/pkg/internal/http/api" "git.solsynth.dev/hypernet/nexus/pkg/internal/http/api"
"github.com/goccy/go-json" "github.com/goccy/go-json"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -42,6 +43,8 @@ func NewServer() *HTTPApp {
Output: log.Logger, Output: log.Logger,
})) }))
app.Use(auth.ContextMiddleware)
api.MapAPIs(app) api.MapAPIs(app)
return &HTTPApp{app} return &HTTPApp{app}