Skip to content

refactor(server): integrate better-auth admin plugin#1873

Merged
luoling8192 merged 4 commits into
mainfrom
rainbowbird/fix/electron-flux-checkout-origin
May 25, 2026
Merged

refactor(server): integrate better-auth admin plugin#1873
luoling8192 merged 4 commits into
mainfrom
rainbowbird/fix/electron-flux-checkout-origin

Conversation

@luoling8192

Copy link
Copy Markdown
Member
  • Simplified adminGuard middleware by removing dependency on environment variables.
  • Introduced new admin user routes for managing user balances, including validation and error handling.
  • Implemented user role checks for admin access, replacing email allowlist checks.
  • Enhanced balance management in billing service to support admin overrides with detailed transaction logging.
  • Added tests for new user management routes and updated existing tests to reflect role-based access control.
  • Updated database schemas to include role and ban management fields for users.

The packaged Electron renderer loads from file://, so its Stripe checkout
and portal requests carry no Referer and an opaque/absent Origin.
resolveTrustedRequestOrigin() returned undefined and the routes threw
INVALID_ORIGIN ("Missing trusted request origin"), blocking FLUX purchases
on desktop. Web and mobile were unaffected because they send a trusted web
origin. CORS was not the blocker: file:// requests already reach the API
(balance, providers, characters all work), so only the checkout-specific
redirect-base dependency failed.

Stripe success_url/cancel_url/return_url must be http(s) URLs, so file://
can never be a valid redirect base. Replace the trusted-origin requirement
with resolveCheckoutRedirectBase(), which prefers the request's trusted
origin (web/mobile return to where they started) and falls back to a
configured canonical web app URL (WEB_APP_URL, default https://airi.moeru.ai)
for origin-less clients like the desktop app.

On the client, the desktop app opens checkout in the system browser via
window.open (routed through setWindowOpenHandler -> shell.openExternal)
instead of navigating the file:// window to Stripe, and refreshes the FLUX
balance on window focus since it never receives the success_url redirect.
- Simplified adminGuard middleware by removing dependency on environment variables.
- Introduced new admin user routes for managing user balances, including validation and error handling.
- Implemented user role checks for admin access, replacing email allowlist checks.
- Enhanced balance management in billing service to support admin overrides with detailed transaction logging.
- Added tests for new user management routes and updated existing tests to reflect role-based access control.
- Updated database schemas to include role and ban management fields for users.
@github-actions

github-actions Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.

Name Link
🔭 Waiting for approval For maintainers, approve here

Hey, maintainers, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏

@github-actions github-actions Bot added feature Related to feature scope/server-api Scope related to the server api we maintained, the public service of AIRI labels May 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e824da01ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/server/src/services/domain/billing/billing-service.ts
@luoling8192 luoling8192 merged commit 0ac9b70 into main May 25, 2026
10 checks passed
@luoling8192 luoling8192 deleted the rainbowbird/fix/electron-flux-checkout-origin branch May 25, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Related to feature scope/server-api Scope related to the server api we maintained, the public service of AIRI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant