Skip to content

✨ feat: remove NextAuth#11732

Merged
tjx666 merged 34 commits intonextfrom
refactor/remove-nextauth
Jan 23, 2026
Merged

✨ feat: remove NextAuth#11732
tjx666 merged 34 commits intonextfrom
refactor/remove-nextauth

Conversation

@tjx666
Copy link
Copy Markdown
Member

@tjx666 tjx666 commented Jan 23, 2026

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

Closes #10456

🔀 Description of Change

This PR removes all NextAuth authentication code and simplifies the codebase since only Better Auth is now supported.

Key changes:

  1. Environment variables cleanup (src/envs/auth.ts):

    • Remove enableNextAuth/enableBetterAuth exports
  2. Source code simplification (12+ files):

    • Remove all conditional checks for enableBetterAuth/enableNextAuth
    • Keep only Better Auth logic
    • Convert dynamic import('@/auth') to static imports
    • Remove isLoginWithBetterAuth selector, use isLogin directly
  3. Deleted files:

    • src/app/[variants]/(auth)/signin/layout.tsx
    • src/app/[variants]/(auth)/reset-password/layout.tsx
    • src/app/[variants]/(auth)/verify-email/layout.tsx
  4. Test updates (10 files):

    • Remove NextAuth-related mocks
    • Remove NextAuth-related test cases
    • Add @/auth mock for Better Auth
  5. Documentation updates:

    • Add migration guide links to legacy.mdx and legacy.zh-CN.mdx
    • Update breaking-changes.mdx and breaking-changes.zh-CN.mdx with migration links

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

Test commands:

bun run type-check
bunx vitest run --silent='passed-only'

📸 Screenshots / Videos

N/A - No UI changes

📝 Additional Information

Breaking changes:

  • NextAuth is no longer supported
  • Users must migrate to Better Auth following the migration guide

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobehub Error Error Jan 24, 2026 0:22am

Request Review

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jan 23, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @tjx666, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@gru-agent
Copy link
Copy Markdown
Contributor

gru-agent bot commented Jan 23, 2026

There is too much information in the pull request to test.

@dosubot dosubot bot added the 📝 Documentation Improvements or additions to documentation label Jan 23, 2026
Copy link
Copy Markdown

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

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: df84d5e59d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +32 to +33
return this.db.query.users.findFirst({
where: eq(account.userId, result.userId),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use users.id when querying users table

When a Logto/Casdoor webhook fires, getUserByAccount queries users with eq(account.userId, result.userId), but account isn’t part of the users query. Drizzle will emit SQL that references the account table without a join (or will never match), so webhook updates/sign-outs will fail to locate the user and either error or silently no-op. This should compare the users table’s primary key (e.g., users.id) to result.userId.

Useful? React with 👍 / 👎.

@tjx666 tjx666 added trigger:build-docker Trigger Docker image build trigger:build-desktop Trigger Desktop build labels Jan 23, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 54.92958% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (0fcf8b0) to head (077bdf7).
⚠️ Report is 3 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next   #11732      +/-   ##
==========================================
+ Coverage   74.16%   74.44%   +0.27%     
==========================================
  Files        1193     1191       -2     
  Lines       95004    94478     -526     
  Branches    12534    12501      -33     
==========================================
- Hits        70464    70334     -130     
+ Misses      24450    24054     -396     
  Partials       90       90              
Flag Coverage Δ
app 67.59% <52.23%> (+0.37%) ⬆️
database 91.48% <ø> (ø)
packages/agent-runtime 90.20% <ø> (ø)
packages/context-engine 85.33% <ø> (ø)
packages/conversation-flow 92.28% <ø> (ø)
packages/file-loaders 87.04% <ø> (ø)
packages/memory-user-memory 69.30% <ø> (ø)
packages/model-bank 100.00% <ø> (ø)
packages/model-runtime 86.72% <ø> (ø)
packages/prompts 79.33% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 93.16% <100.00%> (-0.07%) ⬇️
packages/web-crawler 95.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.99% <96.42%> (+<0.01%) ⬆️
Services 50.69% <ø> (-0.04%) ⬇️
Server 68.51% <50.00%> (+0.80%) ⬆️
Libs 39.99% <33.33%> (-0.38%) ⬇️
Utils 93.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Desktop App Build Completed!

Version: 0.0.0-nightly.pr11732.4131
Build Time: 2026-01-23T09:37:02.223Z

📦 View All Build Artifacts

Build Artifacts

Platform File Size
macOS (Apple Silicon) LobeHub-Nightly-0.0.0-nightly.pr11732.4131-arm64.dmg 106.01 MB
macOS (Intel) LobeHub-Nightly-0.0.0-nightly.pr11732.4131-x64.dmg 111.15 MB
Windows LobeHub-Nightly-0.0.0-nightly.pr11732.4131-setup.exe 103.38 MB
Linux LobeHub-Nightly-0.0.0-nightly.pr11732.4131.AppImage 126.23 MB

Warning

Note: This is a temporary build for testing purposes only.

@tjx666 tjx666 removed trigger:build-desktop Trigger Desktop build trigger:build-docker Trigger Docker image build labels Jan 23, 2026
@tjx666 tjx666 force-pushed the refactor/remove-nextauth branch 2 times, most recently from 91d2c2f to 5416506 Compare January 23, 2026 12:31
@tjx666 tjx666 changed the title 🔥 refactor: remove NextAuth authentication code ✨ feat: remove NextAuth Jan 23, 2026
Add migration tools for users upgrading from NextAuth to Better Auth:

- Migration scripts to transfer SSO connections from nextauth_accounts
  to Better Auth accounts table
- Support for test/prod modes with dry-run capability
- Batch processing with progress tracking for resumable migrations
- Verification script to validate migration results
- Documentation in English and Chinese covering simple and full migration
- Add GitHub Issue link for feedback
- Adjust user threshold to ≤ 10 users (align with Clerk docs)
- Add note about manual re-binding of social accounts
- Consolidate backup and dry-run reminders in Full Migration section
- Simplify Step 6 by referencing Simple Migration steps
- Add green bold for success counts and messages
- Add red bold for failure messages
- Fix NextAuth scope conversion (space → comma separated)
- Use deterministic id for account migration
- Delete src/libs/next-auth/ directory (19 files)
- Delete NextAuth pages (signin, error)
- Delete NextAuth layout provider and components
- Delete NextAuthUserService, replace with WebhookUserService
- Remove nextAuth field from TRPC context
- Remove unlinkSSOProvider endpoint (NextAuth-specific)
- Update middleware to only use Better Auth
- Clean up related tests
- Remove enableNextAuth/enableBetterAuth exports from envs/auth.ts
- Simplify auth route to directly use Better Auth handler
- Remove conditional checks in middleware, context, and actions
- Delete unnecessary layout files for auth pages
- Update tests to remove NextAuth-related mocks and test cases
- Fix profile/index.tsx to use isLoginWithBetterAuth only
- Remove isLoginWithBetterAuth selector, use isLogin instead
- Replace dynamic import('@/auth') with static imports
- Update profile and SSOProvidersList to use isLogin
- Add orderBy to topic.create.test.ts to ensure consistent query order
- Revert getSessionUser.ts to dynamic import to avoid validator ESM/CJS issue during sitemap generation
tjx666 added 19 commits January 23, 2026 23:39
- Remove NEXT_AUTH_* environment variables and fallback logic from auth.ts
- Delete src/envs/auth.test.ts (NextAuth fallback tests)
- Update docker-compose configs to use AUTH_SECRET/AUTH_SSO_PROVIDERS
- Add SSO provider environment variable check in prebuild
- Add docs/self-hosting/advanced/redis/upstash.mdx documentation
Support separate sender address configuration for AWS SES and other
services where SMTP_USER is not a valid email address.
Add environment variable declarations for:
- Redis: REDIS_URL, REDIS_PREFIX, REDIS_TLS
- Email: SMTP_*, RESEND_*, EMAIL_SERVICE_PROVIDER
- Common SSO: Google, GitHub, Microsoft credentials
Support AUTH_ALLOWED_EMAILS env var to restrict registration to
specific emails or domains (e.g., "example.com,admin@other.com")
- Refactor checkDeprecatedAuth.js with config-driven approach
- Detect all NEXT_AUTH*/NEXTAUTH* env vars dynamically
- Add check for NEXT_PUBLIC_AUTH_* deprecated vars
- Remove NEXT_PUBLIC_* fallback in auth.ts
- Use APIError instead of Error in email-whitelist plugin
- Rename NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION to AUTH_EMAIL_VERIFICATION
- Add AUTH_ALLOWED_EMAILS documentation for email whitelist feature
- Add FAQ entry for restricting registration to specific emails/domains
- Replace instances of NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION with AUTH_EMAIL_VERIFICATION in .env.example, e2e configurations, and documentation.
- Update breaking changes documentation to reflect the new variable name for email verification requirement.
…Auth

Add comprehensive environment variable migration reference including:
- General variables mapping (NEXT_AUTH_SECRET → AUTH_SECRET, etc.)
- SSO provider variables (most unchanged, Microsoft renamed)
- New Better Auth feature variables (email whitelist, magic link, etc.)
Replace AdapterAccount type import with local AccountType definition
to completely remove next-auth package dependency.
Rewrite the authentication provider development guide to reflect
the new Better Auth architecture, including:
- Provider definition structure (builtin vs generic)
- Environment variable configuration
- Provider registration process
….20260122.4 and remove unused Session and User imports from auth initial state
Vercel uses Amazon Linux (glibc), not Alpine Linux (musl).
This excludes unnecessary musl binaries saving ~45MB:
- @napi-rs/canvas-*-musl: ~29MB
- @img/sharp-libvips-*musl: ~16MB
Revert temporary changes made for debugging 250MB limit:
- Remove NEXT_DEBUG_FUNCTION_SIZE from vercel.json
- Remove better-call override
- Restore better-auth packages to ^1.4.17
- Restore better-call to ^1.2.0

The outputFileTracingExcludes config is sufficient to fix the issue.
@tjx666 tjx666 force-pushed the refactor/remove-nextauth branch from a167c3a to 077bdf7 Compare January 23, 2026 15:40
@tjx666 tjx666 merged commit 1eff864 into next Jan 23, 2026
36 of 37 checks passed
@tjx666 tjx666 deleted the refactor/remove-nextauth branch January 23, 2026 15:57
@lobehubbot
Copy link
Copy Markdown
Member

❤️ Great PR @tjx666 ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

lobehubbot pushed a commit that referenced this pull request Jan 23, 2026
## [Version&nbsp;2.0.0-next.356](v2.0.0-next.355...v2.0.0-next.356)
<sup>Released on **2026-01-23**</sup>

#### ✨ Features

- **misc**: Remove NextAuth.

#### 🐛 Bug Fixes

- **editor**: Prevent crash when toggling enableInputMarkdown setting.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Remove NextAuth, closes [#11732](#11732) ([1eff864](1eff864))

#### What's fixed

* **editor**: Prevent crash when toggling enableInputMarkdown setting, closes [#11755](#11755) ([ea5eed8](ea5eed8))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.0.0-next.356 🎉

The release is available on:

Your semantic-release bot 📦🚀

JamieStivala pushed a commit to jaworldwideorg/OneJA-Bot that referenced this pull request Jan 23, 2026
## [Version&nbsp;1.154.0](v1.153.1...v1.154.0)
<sup>Released on **2026-01-23**</sup>

#### ♻ Code Refactoring

- **misc**: Migrate AI Rules to Claude Code Skills.

#### ✨ Features

- **database**: Extended async task with metadata and parent id, added index.
- **misc**: Remove NextAuth.

#### 🐛 Bug Fixes

- **copilot**: History popover not refreshing when agentId changes.
- **editor**: Prevent crash when toggling enableInputMarkdown setting.
- **home**: Use correct CreateGroupModal for session group creation.
- **model-runtime**: Handle null content in anthropic message builder.
- **ModelSelect**: Resolve tooltip hover causing popup to close.
- **pdf**: Ensure worker config before Document render.
- **store**: Delete message before regeneration.
- **misc**: Fix auto scroll, fix favorite refresh bug and group topic refresh issue, fixed the agent group builder tools excaution edge case crash, page content switch mismatch, when use market group, the group sys role was not used.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Migrate AI Rules to Claude Code Skills, closes [lobehub#11737](https://github.com/jaworldwideorg/OneJA-Bot/issues/11737) ([346fc46](346fc46))

#### What's improved

* **database**: Extended async task with metadata and parent id, added index, closes [lobehub#11712](https://github.com/jaworldwideorg/OneJA-Bot/issues/11712) ([31d2f26](31d2f26))
* **misc**: Remove NextAuth, closes [lobehub#11732](https://github.com/jaworldwideorg/OneJA-Bot/issues/11732) ([1eff864](1eff864))

#### What's fixed

* **copilot**: History popover not refreshing when agentId changes, closes [lobehub#11731](https://github.com/jaworldwideorg/OneJA-Bot/issues/11731) ([64f39e7](64f39e7))
* **editor**: Prevent crash when toggling enableInputMarkdown setting, closes [lobehub#11755](https://github.com/jaworldwideorg/OneJA-Bot/issues/11755) ([ea5eed8](ea5eed8))
* **home**: Use correct CreateGroupModal for session group creation, closes [lobehub#11752](https://github.com/jaworldwideorg/OneJA-Bot/issues/11752) ([36bcc50](36bcc50))
* **model-runtime**: Handle null content in anthropic message builder, closes [lobehub#11756](https://github.com/jaworldwideorg/OneJA-Bot/issues/11756) ([539753a](539753a))
* **ModelSelect**: Resolve tooltip hover causing popup to close, closes [lobehub#11742](https://github.com/jaworldwideorg/OneJA-Bot/issues/11742) ([1b73f14](1b73f14))
* **pdf**: Ensure worker config before Document render, closes [lobehub#11746](https://github.com/jaworldwideorg/OneJA-Bot/issues/11746) ([ad34072](ad34072))
* **store**: Delete message before regeneration, closes [lobehub#11760](https://github.com/jaworldwideorg/OneJA-Bot/issues/11760) ([a8a6300](a8a6300))
* **misc**: Fix auto scroll, closes [lobehub#11734](https://github.com/jaworldwideorg/OneJA-Bot/issues/11734) ([892fa9f](892fa9f))
* **misc**: Fix favorite refresh bug and group topic refresh issue, closes [lobehub#11745](https://github.com/jaworldwideorg/OneJA-Bot/issues/11745) ([5d115ef](5d115ef))
* **misc**: Fixed the agent group builder tools excaution edge case crash, closes [lobehub#11735](https://github.com/jaworldwideorg/OneJA-Bot/issues/11735) ([5de4742](5de4742))
* **misc**: Page content switch mismatch, closes [lobehub#11758](https://github.com/jaworldwideorg/OneJA-Bot/issues/11758) ([fdc8f95](fdc8f95))
* **misc**: When use market group, the group sys role was not used, closes [lobehub#11739](https://github.com/jaworldwideorg/OneJA-Bot/issues/11739) ([afc76f9](afc76f9))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📝 Documentation Improvements or additions to documentation released on @next size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔐 Unify Authentication to BetterAuth

2 participants