fix phone auth
Some checks failed
build quyun / Build (push) Failing after 1m27s

This commit is contained in:
2025-12-20 13:06:09 +08:00
parent dbeb0a5733
commit 12aa7a404a
6 changed files with 26 additions and 18 deletions

View File

@@ -46,10 +46,9 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
u.Path = "/v1/auth/phone"
fullUrl = u.String()
// check cookie exists
cookie := ctx.Cookies("token")
log.Infof("cookie: %s", cookie)
if cookie == "" {
// 仅使用 Header 的 Bearer Token前端 localStorage 存储,随请求透传)。
token := ctx.Get("Authorization")
if token == "" {
log.Infof("auth redirect_uri: %s", fullUrl)
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
@@ -57,10 +56,8 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
return ctx.Redirect().To(fullUrl)
}
jwt, err := f.jwt.Parse(cookie)
jwt, err := f.jwt.Parse(token)
if err != nil {
// remove cookie
ctx.ClearCookie("token")
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
@@ -69,8 +66,6 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
user, err := services.Users.FindByID(ctx.Context(), jwt.UserID)
if err != nil {
// remove cookie
ctx.ClearCookie("token")
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}