better-auth-kit icon indicating copy to clipboard operation
better-auth-kit copied to clipboard

feat: onboarding plugin

Open jslno opened this issue 1 year ago • 5 comments

Summary by CodeRabbit

  • New Features
    • Introduced an Onboarding plugin with multi-step flows, required/optional steps, one-time completion, optional skip, completion tracking, and client-side redirect hook.
    • Added ready-to-use presets: Setup New Password and Setup 2FA.
  • Documentation
    • New Onboarding plugin docs, sidebar entry, and updated plugin catalog.
  • Tests
    • Added comprehensive tests covering onboarding flows, redirects, required steps, and both presets.
  • Chores
    • Added package configuration, build scripts, license, TypeScript config, and ignore rules for the onboarding package.

Possible future improvements

  • [ ] Branched flows
  • [ ] Ordered flows

jslno avatar Aug 21 '25 17:08 jslno

⚠️ No Changeset found

Latest commit: e9201ab72a6b40ad70956437a734ebdb6ef8cae9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Aug 21 '25 17:08 changeset-bot[bot]

@jslno is attempting to deploy a commit to the ping-maxwell's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Aug 21 '25 17:08 vercel[bot]

Walkthrough

Introduces a new onboarding plugin package with server, client, types, utilities, adapter, and presets. Adds build scripts, configuration, tests, and documentation. Implements endpoints for onboarding steps, access checks, optional skip, session hooks, and storage via internal DB or secondary storage. Updates docs navigation and plugin catalog.

Changes

Cohort / File(s) Summary
Package scaffolding
packages/plugins/onboarding/package.json, .../tsconfig.json, .../.gitignore, .../.npmignore, .../README.md, .../LICENSE
New package manifest, TS config, ignore files, README, and MIT license for the onboarding plugin.
Build tooling
packages/plugins/onboarding/build.ts, .../build-dev.ts
Adds build and dev scripts wiring to internal build tool; exports build config with DTS enabled.
Core server plugin
packages/plugins/onboarding/src/index.ts, .../src/schema.ts, .../src/types.ts, .../src/internal-types.ts, .../src/error-codes.ts
Implements onboarding plugin, schema additions, public types, endpoint/typing utilities, and error codes.
Client plugin
packages/plugins/onboarding/src/client.ts, .../src/utils.ts
Adds client integration: request method coercion, redirect hook, and path utilities (runtime and type-level).
Verification and adapter
packages/plugins/onboarding/src/verify-onboarding.ts, .../src/adapter.ts
Verifies onboarding eligibility with optional secondary storage; adapter abstracts reads/writes for shouldOnboard and completedSteps.
Presets
packages/plugins/onboarding/src/presets/index.ts, .../src/presets/setup-new-password.ts, .../src/presets/setup-2fa.ts
Adds reusable onboarding steps for new password and 2FA; barrels exports.
Tests (core and presets)
packages/plugins/onboarding/tests/auth.ts, .../tests/onboarding.test.ts, .../tests/presets/setup-new-password.test.ts, .../tests/presets/setup-2fa.test.ts
Introduces test helpers and suites covering flows, auto-enable, required steps, presets, and error handling.
Docs content
apps/docs/content/docs/plugins/onboarding.mdx, apps/docs/content/docs/offer.mdx
Adds onboarding plugin documentation; updates plugin catalog/order and status entries.
Docs sidebar
apps/docs/src/components/sidebar-content.tsx
Adds “Onboarding” item with DoorOpen icon to sidebar navigation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant C as Client (onboardingClient)
  participant S as Auth Server (onboarding)
  participant A as Adapter/Storage

  rect rgb(245,248,255)
  note over C,S: Complete onboarding step (POST)
  U->>C: Submit step data
  C->>C: Coerce method to POST for /onboarding/(step|skip-step)
  C->>S: POST /onboarding/step/:path {body}
  S->>S: verifyOnboarding(ctx)
  S->>A: getShouldOnboard(userId)
  A-->>S: shouldOnboard
  S->>S: validate input, once/required checks
  S->>A: updateOnboardingState(userId, {completedSteps,...})
  A-->>S: ok
  S-->>C: { completedSteps, data }
  C-->>U: Show result
  end
sequenceDiagram
  autonumber
  actor U as User
  participant C as Client (onboardingClient)
  participant S as Auth Server (get-session hook)
  participant A as Adapter/Storage

  rect rgb(245,255,245)
  note over C,S: Session retrieval and redirect hint
  U->>C: getSession()
  C->>S: GET /get-session
  S->>A: getShouldOnboard(userId)
  A-->>S: shouldOnboard
  alt shouldOnboard
    S-->>C: session + {onboardingRedirect:true}
    C->>C: onSuccess -> options.onOnboardingRedirect()
  else not onboarding
    S-->>C: session
  end
  end
sequenceDiagram
  autonumber
  participant S as Auth Server (sign-up)
  participant A as Adapter/Storage

  note over S: Auto-enable on sign-up (optional)
  S->>S: create user/session
  alt autoEnableOnSignUp true
    S->>A: updateOnboardingState(userId, {shouldOnboard:true})
    A-->>S: ok
  else disabled
    S-->>S: no-op
  end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

New paths appear, hop-hop, I see—
Steps to take, one, two, and three.
Passwords set and 2FA bright,
Check the session, turn on the light.
When carrots—er, steps—are all complete,
I thump my paw: onboarding’s neat! 🥕🐇

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 21 '25 17:08 coderabbitai[bot]

@coderabbitai review

jslno avatar Aug 22 '25 12:08 jslno

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Aug 22 '25 12:08 coderabbitai[bot]