fix: issues

This commit is contained in:
Rogee
2024-12-13 20:12:57 +08:00
parent 8a48f202f2
commit 13ebc91220
11 changed files with 109 additions and 37 deletions

View File

@@ -1,6 +1,9 @@
package middlewares
import (
_ "embed"
"os"
"path/filepath"
"strings"
"backend/pkg/pg"
@@ -14,9 +17,6 @@ import (
)
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
// 如果请求存在 Authorization 头,则跳过
if len(c.GetReqHeaders()["Authorization"]) != 0 {
return c.Next()
@@ -81,6 +81,13 @@ func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
return errors.Wrap(err, "failed to create token")
}
// TODO: send html with jwt token
return c.SendString(jwtToken)
b, err := os.ReadFile(filepath.Join(f.storagePath.Asset, "index.html"))
if err != nil {
return errors.Wrap(err, "failed to read file")
}
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
c.Set("Content-Type", "text/html")
return c.SendString(html)
}