Skip to main content
Learn how to configure 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

Create src/contexts/sonamu-provider.tsx in your project.

2. Apply to App

Configure SonamuProvider 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. Pass authOptions 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’s signIn method.

Logout Flow

Using Session

Access the auth client via useSonamuContext in components, and use auth.useSession() to query the current session.

File Upload Configuration

Uploader Interface

Extending SonamuFile and UploadParamsBoth SonamuFile and UploadParams can be extended with project-specific fields via TypeScript declaration merging.
Since the frontend imports SonamuFile and UploadParams from @sonamu-kit/react-components, the declaration merging target must be the same module.

FileService Integration

How it works:
  1. Upload files to backend with mutateAsync
  2. Return uploaded file info (SonamuFile[])
  3. useTypeForm automatically uses this uploader

Auto-integration with useTypeForm

When uploader 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

The SD (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 in BaseSonamuProvider makes the SD function type-safe.

Auto-completion

Advanced Configuration

Minimal Setup (Auth Only)

You can omit uploader if file uploads are not needed.
Omitting uploader will cause errors when using FileInput. Always configure it if file upload functionality is 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

Solution: Pass uploader to SonamuProvider.

”auth is not configured” Error

Solution: Pass authOptions to SonamuProvider.

Cannot Find QueryClient

Solution: Place SonamuProvider inside QueryClientProvider.

Next Steps