Skip to content

fix(oauth): return stable error codes - #4825

Open
neow021 wants to merge 2 commits into
QuantumNous:mainfrom
neow021:fix/oauth-login-i18n
Open

fix(oauth): return stable error codes#4825
neow021 wants to merge 2 commits into
QuantumNous:mainfrom
neow021:fix/oauth-login-i18n

Conversation

@neow021

@neow021 neow021 commented May 13, 2026

Copy link
Copy Markdown
Contributor

变更描述 / Description

OAuth 登录和绑定流程里,部分业务错误之前只能从本地化 message 判断。这个改动让后端 OAuth 业务错误同时返回稳定的 i18n key code,default 前端在 GitHub 已绑定账号的兼容登录分支中改为匹配 code,不再依赖中文文案。

变更不改变 OAuth 登录、绑定、注册、session 写入流程,只调整错误响应结构和前端判断条件。

变更类型 / Type of change

  • Bug 修复 (Bug fix)
  • 新功能 (New feature)
  • 性能优化 / 重构 (Refactor)
  • 文档更新 (Documentation)

关联任务 / Related Issue

提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 此 PR 修复 OAuth callback 中依赖中文错误文案判断的问题。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行可用检查;前端 typecheck 因本地 node_modules 缺失 TypeScript 文件无法启动,见下方说明。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

运行证明 / Proof of Work

docker run --rm -v "$PWD":/src -w /src golang:1.26.1-alpine gofmt -w controller/discord.go controller/github.go controller/linuxdo.go controller/oauth.go controller/oidc.go controller/telegram.go

git diff --cached --check

git diff --cached -U0 -- controller/discord.go controller/github.go controller/linuxdo.go controller/oauth.go controller/oidc.go controller/telegram.go web/default/src/routes/oauth/\$provider.tsx | rg "^\+.*[\p{Han}]" || true

docker run --rm -v "$PWD":/src -w /src -e GOCACHE=/tmp/go-cache -e GOMODCACHE=/tmp/go-mod-cache golang:1.26.1-alpine go test ./controller

结果:

ok  github.com/QuantumNous/new-api/controller

前端检查说明:

bun run typecheck
# failed before type checking because local node_modules/typescript/bin/tsc cannot find ../lib/tsc.js

Summary by CodeRabbit

  • Improvements

    • OAuth/OIDC error messages are now localized across providers (Discord, GitHub, Linux DO, Telegram, OIDC).
    • Authentication flows use standardized, translated error responses for clearer guidance.
  • Bug Fixes

    • OAuth callback now reliably detects and handles "already bound" accounts, improving login/bind UX.
    • Telegram login/bind now returns consistent translated errors when an account isn't bound or is deleted.

Review Change Stack

- Return i18n-key codes for OAuth business errors.\n- Stop matching localized Chinese text in the default OAuth callback.\n- Preserve existing OAuth login and binding behavior.
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 553f4e44-3532-4f13-87fb-84fbe229a2eb

📥 Commits

Reviewing files that changed from the base of the PR and between 1b4c43b and f4458db.

📒 Files selected for processing (7)
  • controller/discord.go
  • controller/github.go
  • controller/linuxdo.go
  • controller/oidc.go
  • controller/telegram.go
  • model/user.go
  • web/default/src/routes/oauth/$provider.tsx
✅ Files skipped from review due to trivial changes (1)
  • web/default/src/routes/oauth/$provider.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • controller/linuxdo.go
  • controller/oidc.go
  • controller/github.go
  • controller/discord.go

Walkthrough

This PR systematizes OAuth error handling across provider controllers by replacing hardcoded error messages with i18n-based, context-aware responses, adding local OAuth error writers in the orchestration layer, switching JSON decode/encode to common helpers, and updating the frontend to rely on stable backend error codes for specific flows.

Changes

OAuth Provider i18n Localization

Layer / File(s) Summary
OAuth error response helpers
controller/oauth.go
New local helper functions apiOAuthErrorI18n and writeOAuthErrorI18n emit translated OAuth error JSON with success: false, message, and code fields and support explicit HTTP status codes.
OAuth orchestration integration
controller/oauth.go
HandleOAuth, handleOAuthBind, and handleOAuthError route provider validation and user-status errors through the new translated OAuth error writers.
Discord and GitHub provider i18n migration
controller/discord.go, controller/github.go
Helpers now accept *gin.Context, token/user-info JSON uses common.Marshal/common.DecodeJson, and all OAuth error cases use oauth.NewOAuthError*/common.ApiErrorI18n with i18n keys and provider params.
Linux DO and OIDC provider i18n migration
controller/linuxdo.go, controller/oidc.go
Helpers accept *gin.Context; token and user-info exchange error paths use oauth.NewOAuthError*/common.ApiErrorI18n with i18n keys; JSON decoding switched to common.DecodeJson.
Telegram provider i18n migration
controller/telegram.go
TelegramBind/TelegramLogin return i18n-based API errors, add bound-ID guard in login, and map DB not-found to translated deleted-user errors while keeping success paths unchanged.
Frontend error code matching
web/default/src/routes/oauth/$provider.tsx
Adds OAUTH_ALREADY_BOUND_CODE and changes the non-binding login failure flow to check res.data.code for the "already bound" condition instead of matching localized message.
Model: Telegram lookup behavior
model/user.go
FillUserByTelegramId now returns the raw DB error from First(...) instead of swallowing ErrRecordNotFound and returning a custom nil error.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 Errors used to hop in many tongues,
Now i18n ties their little lungs,
Helpers speak with context clear,
Frontend listens for the code to steer,
Rabbit cheers—translations sung!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.74% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(oauth): return stable error codes' directly and clearly describes the main change—adding stable i18n error codes to OAuth responses—which is the primary objective across all modified OAuth controllers and the frontend.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (8)
controller/linuxdo.go (2)

5-5: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Replace direct encoding/json decoding with common JSON wrappers.

This file still uses json.NewDecoder(...).Decode(...) in controller business code, which violates the repo’s Go JSON rule.

As per coding guidelines, "All JSON marshal/unmarshal operations MUST use wrapper functions from common/json.go ... Do NOT directly import or call encoding/json in business code."

Also applies to: 118-120, 142-144

🤖 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/linuxdo.go` at line 5, This file imports and directly uses
encoding/json via json.NewDecoder(...).Decode(...) (occurrences around lines
referenced) which violates the rule; replace the import and all direct decode
calls with the project JSON wrapper functions from common/json.go (e.g., replace
json.NewDecoder(req.Body).Decode(&obj) with the common wrapper such as
common.DecodeJSON(req.Body, &obj) or the specific wrapper function defined in
common/json.go), remove the direct encoding/json import, and update all
instances in controller/linuxdo.go (including the other occurrences you noted)
to use the common wrapper functions so business code no longer calls
encoding/json directly.

38-41: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

OAuth helper errors are still emitted as plain errors, so stable code can be lost.

getLinuxdoUserInfoByCode returns localized error strings, and callers send them via common.ApiError(c, err). That path usually serializes message-only errors, which breaks the “stable code” contract for OAuth business failures.

Please route these branches through the OAuth i18n error writer (or return a structured OAuth error carrying key/code) so responses consistently include code.

Also applies to: 76-79, 109-111, 122-124, 136-138, 146-148

🤖 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/linuxdo.go` around lines 38 - 41, The handlers currently pass
localized plain errors from getLinuxdoUserInfoByCode (and similar helpers) into
common.ApiError, which strips the stable OAuth error code; instead, when
getLinuxdoUserInfoByCode (and the other call sites noted) returns an
OAuth-related failure, route the response through the OAuth i18n error writer
(or return a structured OAuth error that carries a stable Code/Key and message)
so the HTTP response always includes the stable OAuth code; concretely, replace
calls like common.ApiError(c, err) for OAuth failures with the OAuth i18n writer
(e.g., oauth.I18nErrorWriter(c, err)) or wrap the error in a typed OAuthError {
Code: "...", Message: err } before sending, and apply this change for all
similar branches in linuxdoUser handling.
controller/oidc.go (1)

4-4: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use common JSON wrappers instead of encoding/json in controller code.

json.NewDecoder(...).Decode(...) is still used in this Go business file and should be replaced with the repository’s JSON wrapper utilities.

As per coding guidelines, "All JSON marshal/unmarshal operations MUST use wrapper functions from common/json.go ... Do NOT directly import or call encoding/json in business code."

Also applies to: 67-69, 94-96

🤖 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/oidc.go` at line 4, Remove the direct import of "encoding/json"
and replace all uses of json.NewDecoder(...).Decode(...) (and any
json.NewEncoder(...).Encode(...)) in the oidc controller handlers with the
repository's common JSON wrapper functions; e.g., change
json.NewDecoder(r.Body).Decode(&obj) to the common JSON decode wrapper such as
common.JSONDecode(r.Body, &obj) and change json.NewEncoder(w).Encode(resp) to
common.JSONEncode(w, resp), and update imports to use the common package instead
of "encoding/json" so all marshal/unmarshal calls use the common/json.go
wrappers.
controller/github.go (3)

36-40: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use common.Marshal() instead of encoding/json directly.

Line 37 directly calls json.Marshal(values), which violates the coding guidelines. All JSON marshal operations must use wrapper functions from common/json.go.

♻️ Proposed fix using common.Marshal
-	jsonData, err := json.Marshal(values)
+	jsonData, err := common.Marshal(values)

As per coding guidelines: "Use wrapper functions from common/json.go for all JSON marshal/unmarshal operations: common.Marshal(), common.Unmarshal(), common.UnmarshalJsonStr(), common.DecodeJson(), common.GetJsonType(). Do NOT directly import or call encoding/json in business code."

🤖 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/github.go` around lines 36 - 40, Replace the direct call to
json.Marshal in the GitHub token exchange code: instead of json.Marshal(values)
assign jsonData, err = common.Marshal(values) and handle err as before; update
the surrounding code that uses jsonData (variable jsonData and err) and remove
any direct dependency on encoding/json in controller/github.go so all JSON
marshalling uses the common.Marshal wrapper from common/json.go.

72-76: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use common JSON wrapper instead of encoding/json directly.

Line 73 directly calls json.NewDecoder(res2.Body).Decode(...), which violates the coding guidelines. All JSON unmarshal operations must use wrapper functions from common/json.go.

♻️ Proposed fix using common.DecodeJson
-	var githubUser GitHubUser
-	err = json.NewDecoder(res2.Body).Decode(&githubUser)
-	if err != nil {
+	var githubUser GitHubUser
+	err = common.DecodeJson(res2.Body, &githubUser)
+	if err != nil {

As per coding guidelines: "Use wrapper functions from common/json.go for all JSON marshal/unmarshal operations: common.Marshal(), common.Unmarshal(), common.UnmarshalJsonStr(), common.DecodeJson(), common.GetJsonType(). Do NOT directly import or call encoding/json in business code."

🤖 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/github.go` around lines 72 - 76, The code decodes JSON directly
with json.NewDecoder(res2.Body).Decode(&githubUser) which violates the
guideline; replace that call with the wrapper common.DecodeJson to decode
res2.Body into the githubUser variable (e.g., call common.DecodeJson(res2.Body,
&githubUser)), update any error handling to return the same error, and remove
the direct dependency on encoding/json from imports so only the common JSON
wrapper is used.

56-60: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use common JSON wrapper instead of encoding/json directly.

Line 57 directly calls json.NewDecoder(res.Body).Decode(...), which violates the coding guidelines. All JSON unmarshal operations must use wrapper functions from common/json.go.

♻️ Proposed fix using common.DecodeJson
-	var oAuthResponse GitHubOAuthResponse
-	err = json.NewDecoder(res.Body).Decode(&oAuthResponse)
-	if err != nil {
+	var oAuthResponse GitHubOAuthResponse
+	err = common.DecodeJson(res.Body, &oAuthResponse)
+	if err != nil {

As per coding guidelines: "Use wrapper functions from common/json.go for all JSON marshal/unmarshal operations: common.Marshal(), common.Unmarshal(), common.UnmarshalJsonStr(), common.GetJsonType(). Do NOT directly import or call encoding/json in business code."

🤖 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/github.go` around lines 56 - 60, Replace the direct use of
encoding/json in the GitHub OAuth flow: instead of calling
json.NewDecoder(res.Body).Decode(&oAuthResponse), read the response body into
bytes (from res.Body) and call the common JSON wrapper (e.g.
common.Unmarshal(bodyBytes, &oAuthResponse) or
common.UnmarshalJsonStr(string(bodyBytes), &oAuthResponse)) so all JSON
unmarshalling uses the common package; keep the same GitHubOAuthResponse target
and return error on failure as before.
controller/discord.go (2)

64-68: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use common JSON wrapper instead of encoding/json directly.

Line 65 directly calls json.NewDecoder(res.Body).Decode(...), which violates the coding guidelines. All JSON unmarshal operations must use wrapper functions from common/json.go.

♻️ Proposed fix using common.DecodeJson
-	var discordResponse DiscordResponse
-	err = json.NewDecoder(res.Body).Decode(&discordResponse)
-	if err != nil {
+	var discordResponse DiscordResponse
+	err = common.DecodeJson(res.Body, &discordResponse)
+	if err != nil {

As per coding guidelines: "Use wrapper functions from common/json.go for all JSON marshal/unmarshal operations: common.Marshal(), common.Unmarshal(), common.UnmarshalJsonStr(), common.DecodeJson(), common.GetJsonType(). Do NOT directly import or call encoding/json in business code."

🤖 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/discord.go` around lines 64 - 68, Replace the direct use of
encoding/json decoder when decoding the HTTP response into DiscordResponse:
instead of calling json.NewDecoder(res.Body).Decode(&discordResponse) (and
importing encoding/json), call the wrapper common.DecodeJson to read and
unmarshal the response body into the discordResponse variable; update the code
that declares discordResponse (DiscordResponse) to pass its pointer into
common.DecodeJson and handle/return any error from that call.

91-95: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use common JSON wrapper instead of encoding/json directly.

Line 92 directly calls json.NewDecoder(res2.Body).Decode(...), which violates the coding guidelines. All JSON unmarshal operations must use wrapper functions from common/json.go.

♻️ Proposed fix using common.DecodeJson
-	var discordUser DiscordUser
-	err = json.NewDecoder(res2.Body).Decode(&discordUser)
-	if err != nil {
+	var discordUser DiscordUser
+	err = common.DecodeJson(res2.Body, &discordUser)
+	if err != nil {

As per coding guidelines: "Use wrapper functions from common/json.go for all JSON marshal/unmarshal operations: common.Marshal(), common.Unmarshal(), common.UnmarshalJsonStr(), common.DecodeJson(), common.GetJsonType(). Do NOT directly import or call encoding/json in business code."

🤖 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/discord.go` around lines 91 - 95, The code decodes HTTP response
JSON into DiscordUser using json.NewDecoder(res2.Body).Decode(&discordUser),
which violates the guideline to use common JSON wrappers; replace this direct
call with the wrapper common.DecodeJson on the response body to populate the
variable discordUser (i.e., call common.DecodeJson(res2.Body, &discordUser) or
the equivalent DecodeJson signature), and remove any direct use/import of
encoding/json in the surrounding code or file.
🧹 Nitpick comments (1)
web/default/src/routes/oauth/$provider.tsx (1)

210-210: ⚡ Quick win

Add explicit type annotation for the code variable.

The code variable lacks an explicit type annotation. Per TypeScript guidelines, prefer explicit types over implicit inference to avoid any.

✨ Suggested type annotation
-        const code = res?.data?.code
+        const code: string | undefined = res?.data?.code

As per coding guidelines, avoid any type in TypeScript; prefer specific types or unknown; explicitly annotate parameter and return value types.

🤖 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 `@web/default/src/routes/oauth/`$provider.tsx at line 210, The local variable
"code" (const code = res?.data?.code) in oauth/$provider.tsx should have an
explicit TypeScript type to avoid implicit any; change its declaration to
include an appropriate type (for example const code: string | undefined =
res?.data?.code) and, if the value may be non-string, use a narrower type or use
unknown then validate/cast before use (update any downstream uses in the same
function to handle undefined/null accordingly).
🤖 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.

Inline comments:
In `@controller/oidc.go`:
- Around line 39-42: Replace plain localized errors in getOidcUserInfoByCode
(and the other failing return sites you listed) with a structured OAuth error
that includes a stable machine-readable code plus the localized message; e.g.,
construct and return the project's OAuth error type (something like
common.OAuthError{Code:"invalid_oauth_code", Message:i18n.T(c,
i18n.MsgOAuthInvalidCode)}) or use the existing helper/constructor that builds
OAuth errors, and update each failing return (the empty-code check and the other
error paths at the referenced spots) to return that structured error so
common.ApiError(c, err) emits both the language-agnostic code and the localized
message.

In `@controller/telegram.go`:
- Around line 66-73: The FillUserByTelegramId error is being unconditionally
mapped to the OAuth-deleted business error; update the error handling in the
controller/telegram.go block that calls model.User.FillUserByTelegramId() so
that you distinguish "user not found" (map to i18n.MsgOAuthUserDeleted) from
transient/internal failures (log the actual err and return an appropriate
internal/server error response), e.g., by checking for the model-level sentinel
(like model.ErrUserNotFound) or sql.ErrNoRows and using ApiErrorI18n(c,
i18n.MsgOAuthUserDeleted) only for the not-found case, otherwise call the
internal error handler (and include err details in the log) for other errors.

---

Outside diff comments:
In `@controller/discord.go`:
- Around line 64-68: Replace the direct use of encoding/json decoder when
decoding the HTTP response into DiscordResponse: instead of calling
json.NewDecoder(res.Body).Decode(&discordResponse) (and importing
encoding/json), call the wrapper common.DecodeJson to read and unmarshal the
response body into the discordResponse variable; update the code that declares
discordResponse (DiscordResponse) to pass its pointer into common.DecodeJson and
handle/return any error from that call.
- Around line 91-95: The code decodes HTTP response JSON into DiscordUser using
json.NewDecoder(res2.Body).Decode(&discordUser), which violates the guideline to
use common JSON wrappers; replace this direct call with the wrapper
common.DecodeJson on the response body to populate the variable discordUser
(i.e., call common.DecodeJson(res2.Body, &discordUser) or the equivalent
DecodeJson signature), and remove any direct use/import of encoding/json in the
surrounding code or file.

In `@controller/github.go`:
- Around line 36-40: Replace the direct call to json.Marshal in the GitHub token
exchange code: instead of json.Marshal(values) assign jsonData, err =
common.Marshal(values) and handle err as before; update the surrounding code
that uses jsonData (variable jsonData and err) and remove any direct dependency
on encoding/json in controller/github.go so all JSON marshalling uses the
common.Marshal wrapper from common/json.go.
- Around line 72-76: The code decodes JSON directly with
json.NewDecoder(res2.Body).Decode(&githubUser) which violates the guideline;
replace that call with the wrapper common.DecodeJson to decode res2.Body into
the githubUser variable (e.g., call common.DecodeJson(res2.Body, &githubUser)),
update any error handling to return the same error, and remove the direct
dependency on encoding/json from imports so only the common JSON wrapper is
used.
- Around line 56-60: Replace the direct use of encoding/json in the GitHub OAuth
flow: instead of calling json.NewDecoder(res.Body).Decode(&oAuthResponse), read
the response body into bytes (from res.Body) and call the common JSON wrapper
(e.g. common.Unmarshal(bodyBytes, &oAuthResponse) or
common.UnmarshalJsonStr(string(bodyBytes), &oAuthResponse)) so all JSON
unmarshalling uses the common package; keep the same GitHubOAuthResponse target
and return error on failure as before.

In `@controller/linuxdo.go`:
- Line 5: This file imports and directly uses encoding/json via
json.NewDecoder(...).Decode(...) (occurrences around lines referenced) which
violates the rule; replace the import and all direct decode calls with the
project JSON wrapper functions from common/json.go (e.g., replace
json.NewDecoder(req.Body).Decode(&obj) with the common wrapper such as
common.DecodeJSON(req.Body, &obj) or the specific wrapper function defined in
common/json.go), remove the direct encoding/json import, and update all
instances in controller/linuxdo.go (including the other occurrences you noted)
to use the common wrapper functions so business code no longer calls
encoding/json directly.
- Around line 38-41: The handlers currently pass localized plain errors from
getLinuxdoUserInfoByCode (and similar helpers) into common.ApiError, which
strips the stable OAuth error code; instead, when getLinuxdoUserInfoByCode (and
the other call sites noted) returns an OAuth-related failure, route the response
through the OAuth i18n error writer (or return a structured OAuth error that
carries a stable Code/Key and message) so the HTTP response always includes the
stable OAuth code; concretely, replace calls like common.ApiError(c, err) for
OAuth failures with the OAuth i18n writer (e.g., oauth.I18nErrorWriter(c, err))
or wrap the error in a typed OAuthError { Code: "...", Message: err } before
sending, and apply this change for all similar branches in linuxdoUser handling.

In `@controller/oidc.go`:
- Line 4: Remove the direct import of "encoding/json" and replace all uses of
json.NewDecoder(...).Decode(...) (and any json.NewEncoder(...).Encode(...)) in
the oidc controller handlers with the repository's common JSON wrapper
functions; e.g., change json.NewDecoder(r.Body).Decode(&obj) to the common JSON
decode wrapper such as common.JSONDecode(r.Body, &obj) and change
json.NewEncoder(w).Encode(resp) to common.JSONEncode(w, resp), and update
imports to use the common package instead of "encoding/json" so all
marshal/unmarshal calls use the common/json.go wrappers.

---

Nitpick comments:
In `@web/default/src/routes/oauth/`$provider.tsx:
- Line 210: The local variable "code" (const code = res?.data?.code) in
oauth/$provider.tsx should have an explicit TypeScript type to avoid implicit
any; change its declaration to include an appropriate type (for example const
code: string | undefined = res?.data?.code) and, if the value may be non-string,
use a narrower type or use unknown then validate/cast before use (update any
downstream uses in the same function to handle undefined/null accordingly).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6153a012-4707-4756-b78f-d7c88448907a

📥 Commits

Reviewing files that changed from the base of the PR and between aa56667 and 1b4c43b.

📒 Files selected for processing (7)
  • controller/discord.go
  • controller/github.go
  • controller/linuxdo.go
  • controller/oauth.go
  • controller/oidc.go
  • controller/telegram.go
  • web/default/src/routes/oauth/$provider.tsx

Comment thread controller/oidc.go
Comment thread controller/telegram.go
- Replace direct encoding/json calls with common JSON wrappers in OAuth controllers.\n- Return typed OAuth errors so machine-readable codes survive controller responses.\n- Distinguish Telegram not-found and internal lookup failures.
@neow021

neow021 commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the current review feedback in f4458db7:

  • replaced direct encoding/json calls in the touched OAuth controllers with common JSON wrappers
  • returned typed OAuth errors from provider-specific controller helpers so stable codes survive response handling
  • distinguished Telegram lookup not-found vs internal failure
  • added the explicit TypeScript annotation for the frontend code variable

Validation rerun:

  • go test ./controller ./model
  • bun run typecheck is still blocked in this temp clone because local node_modules/typescript/bin/tsc cannot find ../lib/tsc.js before type checking starts

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant