SonamuProvider, the starting point for Sonamu frontend integration. Configure authentication, file uploads, and internationalization in one place.
Setup Overview
Auth Integration
Connect UserService.useMeLogin/logout flow
File Upload
FileService integrationAuto-connect to useTypeForm
Internationalization
SD function providerType-safe translations
Global State
Context API basedAccess from all components
Basic Setup
1. Create SonamuProvider Config File
Createsrc/contexts/sonamu-provider.tsx in your project.
2. Apply to App
ConfigureSonamuProvider in __root.tsx.
Why create a separate SonamuProvider file?
SonamuProvider uses React hooks like FileService.useUploadMutation(), so it must be placed under QueryClientProvider.
Separating it into its own file allows you to co-locate authOptions, useSonamuContext, and type definitions.Auth Configuration
Sonamu uses better-auth for authentication. PassauthOptions to SonamuProvider and a better-auth client is created internally.
Defining authOptions
Define better-auth client options. You can extend user fields through plugins.What is
inferAdditionalFields?It adds project-specific fields (like role) to the client-side User type beyond better-auth defaults (id, name, email, etc.).
These should match the user schema defined on the server.Login Flow
Use the better-auth client’ssignIn method.
Logout Flow
Using Session
Access the auth client viauseSonamuContext in components, and use auth.useSession() to query the current session.
File Upload Configuration
Uploader Interface
Extending SonamuFile and UploadParamsBoth Since the frontend imports
SonamuFile and UploadParams can be extended with project-specific fields via TypeScript declaration merging.SonamuFile and UploadParams from @sonamu-kit/react-components, the declaration merging target must be the same module.FileService Integration
- Upload files to backend with
mutateAsync - Return uploaded file info (
SonamuFile[]) useTypeFormautomatically uses this uploader
Auto-integration with useTypeForm
Whenuploader is configured, useTypeForm’s submit automatically uploads files.
Auto-upload MechanismThe
submit function internally calls traverseAndUploadFiles to find and upload all File objects.
Files in nested objects or arrays are automatically handled.Custom Upload Logic
You can implement your own if using a different upload service.Internationalization (SD)
SD Function
TheSD (Sonamu Dictionary) function provides type-safe translations.
Usage Example
Why provide SD through Context?While you can import and use it directly, using Context makes it easy to add runtime locale switching or dynamic dictionary loading in the future.
Type Safety
Specify Generic Type
Specifying the Dictionary type inBaseSonamuProvider makes the SD function type-safe.
Auto-completion
Advanced Configuration
Minimal Setup (Auth Only)
You can omituploader if file uploads are not needed.
Using Without Auth
If authentication isn’t needed,authOptions can be omitted.
Display Loading State
Customize Redirect
You can dynamically determine the redirect path after successful login.Troubleshooting
”uploader is not configured” Error
uploader to SonamuProvider.
”auth is not configured” Error
authOptions to SonamuProvider.
Cannot Find QueryClient
SonamuProvider inside QueryClientProvider.
Next Steps
- useTypeForm - Form management and file uploads
- useListParams - List filtering
- Auth API Development - Backend auth setup
- File Upload API - Backend storage setup