fix(auth): localize WeChat OAuth messages#4907
Conversation
- Route current-user WeChat and custom OAuth responses through backend i18n. - Add matching en, zh-CN, and zh-TW messages. - Keep admin custom OAuth management endpoints unchanged.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR adds internationalization support to custom OAuth and WeChat authentication flows by introducing new i18n message keys, providing translations across multiple locales, and updating controller error and success responses to use locale-aware messaging instead of hardcoded strings. ChangesOAuth/WeChat i18n Support
Sequence DiagramsequenceDiagram
participant WeChatAuth as WeChatAuth/WeChatBind
participant getWeChatIdByCode as getWeChatIdByCode
participant apiWeChatError as apiWeChatError
participant ApiErrorI18n as ApiErrorI18n
WeChatAuth->>getWeChatIdByCode: call with code
alt Invalid Code
getWeChatIdByCode-->>WeChatAuth: errWeChatInvalidCode
else Verification Failed
getWeChatIdByCode-->>WeChatAuth: errWeChatVerificationFailed
end
WeChatAuth->>apiWeChatError: map sentinel error
apiWeChatError->>ApiErrorI18n: translate to i18n response
ApiErrorI18n-->>WeChatAuth: localized API error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
controller/wechat.go (1)
31-50:⚠️ Potential issue | 🟠 Major | ⚡ Quick winUse
common.DecodeJsoninstead ofencoding/jsonin controller code.Line 49 uses
json.NewDecoder(...).Decode(&res), which violates the project's requirement that all JSON operations in business code must use wrapper functions fromcommon/json.go.Proposed fix
import ( - "encoding/json" "errors" "fmt" "net/http" "net/url" @@ var res wechatLoginResponse - err = json.NewDecoder(httpResponse.Body).Decode(&res) + err = common.DecodeJson(httpResponse.Body, &res) if err != nil { return "", err }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@controller/wechat.go` around lines 31 - 50, The function getWeChatIdByCode uses encoding/json directly (json.NewDecoder(...).Decode(&res)); replace that decoding with the project's wrapper: call common.DecodeJson(httpResponse.Body, &res) and handle its returned error similarly. Update references to wechatLoginResponse and ensure you still defer httpResponse.Body.Close() and propagate the error from common.DecodeJson in the same manner the current code does.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@controller/wechat.go`:
- Around line 31-50: The function getWeChatIdByCode uses encoding/json directly
(json.NewDecoder(...).Decode(&res)); replace that decoding with the project's
wrapper: call common.DecodeJson(httpResponse.Body, &res) and handle its returned
error similarly. Update references to wechatLoginResponse and ensure you still
defer httpResponse.Body.Close() and propagate the error from common.DecodeJson
in the same manner the current code does.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3484d3e1-35bb-469e-94eb-11dd61d26094
📒 Files selected for processing (6)
controller/custom_oauth.gocontroller/wechat.goi18n/keys.goi18n/locales/en.yamli18n/locales/zh-CN.yamli18n/locales/zh-TW.yaml
- Decode WeChat login responses through common.DecodeJson. - Remove direct encoding/json use from the touched controller.
Important
📝 变更描述 / Description
Localize user-facing WeChat OAuth login/bind responses and current-user custom OAuth binding responses through the existing backend i18n layer.
This removes hardcoded Chinese responses from ordinary user auth flows, adds matching
en,zh-CN, andzh-TWlocale keys, and keeps admin custom OAuth provider management endpoints unchanged.🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
gofmt -w controller/custom_oauth.go controller/wechat.go i18n/keys.gogo test ./controller ./i18ngit diff --checki18n/locales/en.yaml,zh-CN.yaml, andzh-TW.yamlSummary by CodeRabbit