Repository navigation
[WIP] [Feat] Built-in auth w/ email service - #540
Conversation
WalkthroughAdds a new standalone "auth" workspace (Vite/React/Tailwind) with built-in auth UI, cross-tab BroadcastChannel support, backend auth API and OTP refactors (token exchange, public/admin config split), shared-schema and OpenAPI updates, frontend admin auth UI/service replacements, docs, DB migration, and Docker/dev updates. Changes
Sequence Diagram(s)sequenceDiagram
participant TabA as Browser (Tab A)
participant AuthUI as Auth UI (/auth)
participant Backend as Backend API
participant Broadcast as BroadcastChannel
participant TabB as Browser (Tab B)
TabA->>AuthUI: Open /auth (sign-in / sign-up)
AuthUI->>Backend: POST /api/auth/sessions or POST /api/auth/users
Backend-->>AuthUI: { user, accessToken?, requireEmailVerification?, redirectTo? }
alt requireEmailVerification
AuthUI->>Backend: POST /api/auth/email/send-verification
Backend-->>TabB: (email with code or link)
TabB->>Backend: POST /api/auth/email/verify or exchange code -> token -> POST /reset-password
Backend-->>TabB: { user, accessToken }
TabB->>Broadcast: broadcast(EMAIL_VERIFIED_SUCCESS, { accessToken, user })
Broadcast->>AuthUI: EMAIL_VERIFIED_SUCCESS
AuthUI->>TabA: navigate(redirectTo with tokens)
end
opt Password reset (code flow)
AuthUI->>Backend: POST /api/auth/email/send-reset-password
AuthUI->>Backend: POST /api/auth/email/exchange-reset-password-token { email, code }
Backend-->>AuthUI: { token, expiresAt }
AuthUI->>Backend: POST /api/auth/email/reset-password { newPassword, token }
Backend-->>AuthUI: Success
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Areas needing extra attention:
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✨ 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 |
d4af5b3 to
6482cdf
Compare
790366b to
eab040b
Compare
Fermionic-Lyu
left a comment
There was a problem hiding this comment.
Early reviews. Again, you should put all OSS public auth page into a separate folder. This way your work is isoloated from the main OSS dashboard which makes it easy to test and won't break current working features. Moreover, you should install your auth component package in that mini auth app, so you don't have to rewrite the UI and styles, they are always synced. This is a good way to test your auth component package as well.
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
auth/package.json (1)
1-11: Missing"private": trueto prevent accidental publishing.This workspace package should be marked as private since it's an internal monorepo package not intended for npm publication.
Apply this diff:
{ "name": "insforge-auth", "version": "1.0.0", + "private": true, "author": "Insforge", "description": "Built-in authentication UI for Insforge users", "type": "module",
🧹 Nitpick comments (2)
docs/core-concepts/authentication/ui-components/react.mdx (2)
98-100: Consider hyphenating "sign in" and "sign out" for consistency.Lines 98–100 reference "sign in" and "sign out" as verb phrases. For consistency with the hyphenated forms used in URLs and component names throughout the documentation (
/sign-in,<SignIn>, etc.), consider hyphenating these as "sign-in" and "sign-out" when used as gerunds/nominals in this context. This aligns with compound-modifier style guidance and improves visual consistency.- - `afterSignInUrl` (required): Redirect URL after successful sign in (default: `'/'`) - - `onSignIn` (optional): Custom function to sync token on sign in - - `onSignOut` (optional): Custom function to clear auth state on sign out + - `afterSignInUrl` (required): Redirect URL after successful sign-in (default: `'/'`) + - `onSignIn` (optional): Custom function to sync token on sign-in + - `onSignOut` (optional): Custom function to clear auth state on sign-out
484-484: Hyphenate "sign out" for consistency (line 484).For consistency with the suggestion above and with URL/component naming conventions, change "after sign out" to "after sign-out".
- - `afterSignOutUrl` - Redirect URL after sign out + - `afterSignOutUrl` - Redirect URL after sign-out
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
auth/package.json(1 hunks)docs/core-concepts/authentication/ui-components/react.mdx(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/use[A-Z]*.ts : Hook files must be named usePascalCase.ts (e.g., useAuth.ts)
Applied to files:
docs/core-concepts/authentication/ui-components/react.mdx
🪛 LanguageTool
docs/core-concepts/authentication/ui-components/react.mdx
[grammar] ~98-~98: Use a hyphen to join words.
Context: ...red): Redirect URL after successful sign in (default: '/') - onSignIn (option...
(QB_NEW_EN_HYPHEN)
[grammar] ~99-~99: Use a hyphen to join words.
Context: ...): Custom function to sync token on sign in - onSignOut (optional): Custom func...
(QB_NEW_EN_HYPHEN)
[grammar] ~100-~100: Use a hyphen to join words.
Context: ...tom function to clear auth state on sign out ### Step 2: Configure Router (Built...
(QB_NEW_EN_HYPHEN)
[grammar] ~484-~484: Use a hyphen to join words.
Context: ...terSignOutUrl- Redirect URL after sign out ###` Complete ...
(QB_NEW_EN_HYPHEN)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build-and-push
- GitHub Check: CI Pre-merge Check
- GitHub Check: E2E Tests
🔇 Additional comments (3)
docs/core-concepts/authentication/ui-components/react.mdx (1)
1-772: File review: Documentation is comprehensive and well-structured.The documentation effectively covers setup (provider, router, hooks), built-in auth flow, custom UI alternatives, and full component/hook APIs with TypeScript examples. Previous issues (env var mismatch, missing comma, typo) have been resolved. The tone and structure are well-suited for both human developers and AI agents, with clear Quick Start, alternative patterns, and detailed API reference sections. Code examples are syntactically sound and follow React best practices.
auth/package.json (2)
12-18: The review comment's premise appears incorrect based on verification results.The verification shows that only the
authworkspace explicitly declares@insforge/reactand@insforge/shared-schemasas dependencies. Neitherfrontendnorbackenddeclares these packages as npm dependencies. Frontend has no@insforgepackages at all, and backend uses a tsconfig path mapping instead of a declared dependency.Therefore, there is no cross-workspace version alignment issue to verify—the concern about ensuring "consistent versions across other workspace packages" does not apply, as those packages don't declare these dependencies. The only relevant observation is an internal transitive dependency mismatch within auth itself: auth directly depends on
@insforge/shared-schemas@^1.1.19, while its transitive dependency@insforge/react@^0.4.11requires@insforge/shared-schemas@^1.1.15, but this is a separate concern from cross-workspace alignment.Likely an incorrect or invalid review comment.
19-27: Project configuration is correct for React 19, but watch for Vite 7.0.5 import resolution regressions.The TypeScript configuration correctly uses
"jsx": "react-jsx"(the new transform required for React 19.2.2), and @vitejs/plugin-react is properly integrated in vite.config.ts. However, Vite 7.0.5 has reported regressions in dependency/import resolution that can cause "Failed to resolve import …" errors. During testing, monitor for import resolution failures; if encountered, try temporarily downgrading Vite to 7.0.4 or apply any workaround mentioned in the linked Vite issue until a patch is released.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Fermionic-Lyu
left a comment
There was a problem hiding this comment.
Tested many rounds. Should be good for a first release
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
docs/core-concepts/authentication/ui-components/react.mdx (4)
61-62: Fix Note block code fence formatting.The bash code block is improperly formatted on a single line within the Note block. Move the opening and closing fences to separate lines for correct markdown rendering.
<Note> - **Required Dependencies:** ```bash npm install react@^19.0.0 react-dom@^19.0.0 - react-router-dom@^7.9.0 ``` + **Required Dependencies:** + + ```bash + npm install react@^19.0.0 react-dom@^19.0.0 react-router-dom@^7.9.0 + ``` </Note>
98-100: Use hyphens in "sign-in" and "sign-out" when used as noun phrases.In documentation, compound words like "sign-in" and "sign-out" should be hyphenated when used as nouns or modifiers. Standardizing this improves consistency and aligns with technical writing conventions.
- `afterSignInUrl` (required): Redirect URL after successful sign in (default: `'/'`) - `onSignIn` (optional): Custom function to sync token on sign in - `onSignOut` (optional): Custom function to clear auth state on sign out + `afterSignInUrl` (required): Redirect URL after successful sign-in (default: `'/'`) + `onSignIn` (optional): Custom function to sync token on sign-in + `onSignOut` (optional): Custom function to clear auth state on sign-out
484-484: Hyphenate "sign-out" in props description.For consistency with the hyphenation pattern used in technical documentation, update this reference:
- `afterSignOutUrl` - Redirect URL after sign out + `afterSignOutUrl` - Redirect URL after sign-out
655-678: Clarify the purpose ofusePublicAuthConfighook.The hook description at line 655 ("Get your authentication config in InsForge") could be more explicit. Consider rewording to clarify that this hook retrieves public (non-sensitive) auth configuration from the backend, which is useful primarily for conditional rendering of OAuth providers and password policies in sign-in/sign-up flows. This helps avoid misuse in other contexts.
The warning at line 680-681 already addresses performance, but the purpose clarity could be improved:
### `usePublicAuthConfig()` -Get your authentication config in InsForge: +Fetch public authentication configuration (OAuth providers, email settings) from your backend:auth/src/components/ErrorCard.tsx (1)
8-37: Well-implemented error card component.The component is clean, follows coding guidelines (PascalCase, TypeScript types, proper structure), and includes good dark mode support. The decorative icon correctly uses
aria-hidden="true".Consider adding
role="alert"to the outer container for better accessibility—screen readers will announce error messages immediately when they appear.Apply this diff to enhance accessibility:
export function ErrorCard({ title = 'Error', children }: ErrorCardProps) { return ( - <div className="w-full max-w-md mx-auto"> + <div className="w-full max-w-md mx-auto" role="alert"> <div className="bg-white dark:bg-neutral-800 rounded-lg shadow-lg border border-red-200 dark:border-red-800 p-6">
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
auth/src/App.tsx(1 hunks)auth/src/components/ErrorCard.tsx(1 hunks)auth/src/components/Layout.tsx(1 hunks)auth/src/pages/ForgotPasswordPage.tsx(1 hunks)auth/src/pages/ResetPasswordPage.tsx(1 hunks)auth/src/pages/SignInPage.tsx(1 hunks)auth/src/pages/SignUpPage.tsx(1 hunks)auth/src/pages/VerifyEmailPage.tsx(1 hunks)docs/core-concepts/authentication/ui-components/react.mdx(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- auth/src/pages/SignUpPage.tsx
- auth/src/pages/SignInPage.tsx
- auth/src/pages/VerifyEmailPage.tsx
- auth/src/pages/ForgotPasswordPage.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use TypeScript for all code files
Use ES modules (import/export syntax)
Prefer descriptive, unabbreviated variable and function names
Implement proper error handling with try-catch blocks and logging where appropriate
Use single quotes for strings
Include semicolons at the end of statements
Use arrow functions for callbacks and inline functions
Prefer const over let; avoid var
Use template literals for string interpolation
Maintain 2-space indentation
Format code with the repository Prettier configuration
Variables, parameters, properties, and functions must use camelCase
Constants and enum members must use UPPER_CASE
Include JSDoc comments for complex functions
Files:
auth/src/App.tsxauth/src/components/ErrorCard.tsxauth/src/pages/ResetPasswordPage.tsxauth/src/components/Layout.tsx
**/*.{tsx,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
React components and TypeScript types/interfaces must use PascalCase
Files:
auth/src/App.tsxauth/src/components/ErrorCard.tsxauth/src/pages/ResetPasswordPage.tsxauth/src/components/Layout.tsx
🧠 Learnings (4)
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/api/**/*.ts : Implement authentication and error-handling middleware
Applied to files:
auth/src/App.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.tsx : Implement proper loading and error states in UI
Applied to files:
auth/src/components/ErrorCard.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.tsx : Follow component composition patterns; keep components focused and single-purpose
Applied to files:
auth/src/components/Layout.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/use[A-Z]*.ts : Hook files must be named usePascalCase.ts (e.g., useAuth.ts)
Applied to files:
docs/core-concepts/authentication/ui-components/react.mdx
🧬 Code graph analysis (1)
auth/src/App.tsx (6)
auth/src/components/Layout.tsx (1)
Layout(7-13)auth/src/pages/SignInPage.tsx (1)
SignInPage(7-55)auth/src/pages/SignUpPage.tsx (1)
SignUpPage(7-55)auth/src/pages/VerifyEmailPage.tsx (1)
VerifyEmailPage(5-20)auth/src/pages/ForgotPasswordPage.tsx (1)
ForgotPasswordPage(3-11)auth/src/pages/ResetPasswordPage.tsx (1)
ResetPasswordPage(3-11)
🪛 LanguageTool
docs/core-concepts/authentication/ui-components/react.mdx
[grammar] ~98-~98: Use a hyphen to join words.
Context: ...red): Redirect URL after successful sign in (default: '/') - onSignIn (option...
(QB_NEW_EN_HYPHEN)
[grammar] ~99-~99: Use a hyphen to join words.
Context: ...): Custom function to sync token on sign in - onSignOut (optional): Custom func...
(QB_NEW_EN_HYPHEN)
[grammar] ~100-~100: Use a hyphen to join words.
Context: ...tom function to clear auth state on sign out ### Step 2: Configure Router (Built...
(QB_NEW_EN_HYPHEN)
[grammar] ~484-~484: Use a hyphen to join words.
Context: ...terSignOutUrl- Redirect URL after sign out ###` Complete ...
(QB_NEW_EN_HYPHEN)
🔇 Additional comments (5)
docs/core-concepts/authentication/ui-components/react.mdx (1)
1-772: Documentation quality and completeness — LGTM.The documentation is well-structured, comprehensive, and appropriate for the new
@insforge/reactpackage. The examples are clear, the quick-start flow is practical, and the split between built-in auth and custom UI approaches is well-explained. React 19 alignment, router patterns, and TypeScript integration are all correctly presented.auth/src/components/ErrorCard.tsx (1)
1-6: LGTM! Clean interface definition.The interface follows TypeScript best practices with appropriate types for a presentational component.
auth/src/pages/ResetPasswordPage.tsx (1)
1-11: LGTM! Clean wrapper following established patterns.The component correctly wraps the
ResetPasswordcomponent from@insforge/reactand provides error logging consistent with other auth pages in this PR (SignInPage, SignUpPage, etc.).auth/src/App.tsx (2)
9-15: Excellent use of enum for route paths.Using
AuthRouterPathenum provides type safety and a single source of truth for all auth-related routes. This is a best practice that prevents typos and makes refactoring easier.
17-30: No issues found—all routes properly use the AuthRouterPath enum.Verification confirms that the codebase consistently uses
AuthRouterPathenum values throughout. No hardcoded path strings, non-hyphenated paths, or inconsistencies were found in the source code. The routing structure inauth/src/App.tsxproperly implements the enum, and all paths are consistently hyphenated.
Summary
How did you test this change?
Summary by CodeRabbit
New Features
Documentation