Configuration
Configure authentication for your application.
TurboStarter supports three different authentication methods:
- Password - the traditional email/password method
- Magic Link - passwordless email link authentication
- OAuth - OAuth providers, Google and Github are set up by default
All authentication methods are enabled by default, but you can easily customize them to your needs. You can enable or disable any method, and configure them according to your requirements.
Remember that you can mix and match these methods or add new ones - for example, you can have both password and magic link authentication enabled at the same time, giving your users more flexibility in how they authenticate.
Authentication configuration can be customized through a simple configuration file. The following sections explain the available options and how to configure each authentication method based on your requirements.
API
The server-side authentication configuration is set at packages/auth/src/server.ts
. It confgures Better Auth package to use the correct providers and settings:
The configuration is validated against Better Auth's schema at runtime, providing immediate feedback if any settings are incorrect or insecure. This validation ensures your authentication setup remains robust and properly configured.
All authentication routes and handlers are centralized within the Hono API, giving you a single source of truth and complete control over the authentication flow. This centralization makes it easier to maintain, debug, and customize the authentication process as needed.
Read more about it in the official documentation.
UI
We have separate configuration that determines what is displayed to your users in the UI. It's set at apps/web/config/auth.ts
.
The recommendation is to not update this directly - instead, please define the environment variables and override the default behavior.
The configuration is also validated using the Zod schema, so if something is off, you'll see the errors.
For example, if you want to switch from password to magic link, you'd set the following environment variables:
To display third-party providers in the UI, you need to set the oAuth
array to include the provider you want to display. The default is Google and Github:
Third party providers
To enable third-party authentication providers, you'll need to:
- Set up an OAuth application in the provider's developer console (like Google Cloud Console, Github Developer Settings or any other provider you want to use)
- Configure the corresponding environment variables in your TurboStarter application
Each OAuth provider requires its own set of credentials and environment variables. Please refer to the Better Auth documentation for detailed setup instructions for each supported provider.
Environment variables
Make sure to set both development and production environment variables appropriately. Your OAuth provider may require different callback URLs for each environment.
Last updated on