Authentication Components
This document covers the reusable React components for authentication and authorization in the BuildAppsWith platform. These components handle common auth UI patterns such as sign-in forms, protected routes, and role-based UI elements.Form Components
SignInForm
A complete sign-in form component with validation and error handling.Props
| Prop | Type | Default | Description |
|---|---|---|---|
redirectTo | string | '/' | Path to redirect after successful sign-in |
appearance | 'default' | 'minimal' | 'modal' | 'default' | Visual style of the form |
onSuccess | (userId: string) => void | undefined | Callback after successful sign-in |
onError | (error: string) => void | undefined | Callback after sign-in error |
className | string | '' | Additional CSS classes |
SignUpForm
A complete sign-up form component with validation and error handling.Props
| Prop | Type | Default | Description |
|---|---|---|---|
redirectTo | string | '/' | Path to redirect after successful sign-up |
appearance | 'default' | 'minimal' | 'modal' | 'default' | Visual style of the form |
onSuccess | (userId: string) => void | undefined | Callback after successful sign-up |
onError | (error: string) => void | undefined | Callback after sign-up error |
className | string | '' | Additional CSS classes |
ForgotPasswordForm
A form component for requesting password reset emails.Props
| Prop | Type | Default | Description |
|---|---|---|---|
appearance | 'default' | 'minimal' | 'modal' | 'default' | Visual style of the form |
onSuccess | () => void | undefined | Callback after successful submission |
onError | (error: string) => void | undefined | Callback after error |
className | string | '' | Additional CSS classes |
Protection Components
ProtectedRoute
A component wrapper that ensures routes are only accessible to authenticated users.Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Required | Content to show for authenticated users |
redirectTo | string | '/login' | Path to redirect unauthenticated users |
requiredRole | UserRole | undefined | Required role (optional) |
requiredPermission | Permission | undefined | Required permission (optional) |
fallback | ReactNode | null | Content to show during auth loading |
RoleGate
A component to conditionally render content based on user roles.Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Required | Content to show for users with the allowed role |
allowedRole | UserRole | Required | Required role to see the content |
fallback | ReactNode | null | Content to show for users without the role |
PermissionGate
A component to conditionally render content based on user permissions.Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Required | Content to show for users with the permission |
requiredPermission | Permission | Required | Required permission to see the content |
fallback | ReactNode | null | Content to show for users without the permission |
User Interface Components
UserAvatar
Displays a user’s avatar with authentication state handling.Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Size of the avatar |
fallback | ReactNode | <DefaultAvatar /> | Content to show for unauthenticated users |
className | string | '' | Additional CSS classes |
UserProfile
Displays user profile information with authentication state handling.Props
| Prop | Type | Default | Description |
|---|---|---|---|
appearance | 'default' | 'compact' | 'card' | 'default' | Visual style of the profile |
withSignOut | boolean | false | Whether to show sign-out button |
className | string | '' | Additional CSS classes |
SignOutButton
A button to sign out the current user.Props
| Prop | Type | Default | Description |
|---|---|---|---|
redirectTo | string | '/' | Path to redirect after sign-out |
label | string | 'Sign Out' | Button label |
onClick | () => void | undefined | Additional click handler |
className | string | '' | Additional CSS classes |
Status Components
AuthStatus
Displays the current authentication status.Props
| Prop | Type | Default | Description |
|---|---|---|---|
appearance | 'default' | 'compact' | 'text' | 'default' | Visual style of the status |
className | string | '' | Additional CSS classes |
Message Components
AuthError
Displays authentication error messages.Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | '' | Error message to display |
code | string | '' | Error code (translates to a message) |
className | string | '' | Additional CSS classes |
AuthSuccess
Displays authentication success messages.Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | '' | Success message to display |
className | string | '' | Additional CSS classes |
Implementation Examples
Complete Authentication Page
Protected Dashboard
Navigation with Auth-Aware Links
Best Practices
- Use composition for complex auth UIs - Combine smaller components
- Always handle loading states - Show skeletons or spinners during auth checks
- Provide meaningful fallbacks - Show helpful messages when access is denied
- Use typed props - Leverage TypeScript for component props
- Maintain accessibility - Ensure all auth components are accessible