0xfurai / 0xfurai/peekaping

[Bug] Fix JWT middleware context parameter in VerifyToken call

未關閉 適合新手
#211 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Go
星號
1.2k
分支
69
PR 合併指標
30 天內沒有已合併 PR

描述

**Describe the bug**
The JWT middleware in `apps/server/src/modules/auth/middleware.go` at line 52 is incorrectly passing a `*gin.Context` instead of `context.Context` to the `VerifyToken` method. While this works due to Go's interface compatibility, it violates Go best practices for context handling and is inconsistent with the API Key middleware which was correctly fixed to use `c.Request.Context()`.

**Database**
N/A - Code issue

**To Reproduce**
Steps to reproduce the behavior:
1. Open `apps/server/src/modules/auth/middleware.go`
2. Look at line 52: `claims, err := p.tokenMaker.VerifyToken(c, accessToken, "access")`
3. Check the `VerifyToken` method signature in `jwt.go` which expects `context.Context`
4. Compare with the API Key middleware which correctly uses `c.Request.Context()`

**Expected behavior**
The JWT middleware should pass `c.Request.Context()` to the `VerifyToken` method, following Go conventions for context propagation and maintaining consistency with the API Key middleware implementation.

**Screenshots**
N/A - Code issue

**Desktop (please complete the following information):**
- OS: Any
- Browser N/A
- Version N/A

**Smartphone (please complete the following information):**
- Device: N/A
- OS: N/A
- Browser: N/A
- Version: N/A

**Additional context**
This issue was discovered while working on API Key authentication tests. The API Key middleware had the same problem but was correctly fixed to use `c.Request.Context()` (see line 43 in `api_key/middleware.go`). The JWT middleware should follow the same pattern for consistency and proper context handling. The fix is simple: change `c` to `c.Request.Context()` on line 52.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

The issue is in `apps/server/src/modules/auth/middleware.go` at line 52. Compare with the correct usage in `api_key/middleware.go` line 43. Change the first argument to `VerifyToken` from `c` to `c.Request.Context()`. Run the project's tests to ensure the change doesn't break anything.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
go
領域
api, authentication, backend
Issue 類型
缺陷
難度
1/5
預估耗時
1 小時以內
活躍度
停滯
描述清晰度
描述清楚
新手友好度
70/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。