Authentication
ShipSaaS uses Better Auth for authentication, which is a TypeScript-native authentication library.
Environment Variables
Section titled “Environment Variables”Generate a random secret and add it to your environment variable file:
openssl rand -base64 32.env
BETTER_AUTH_SECRET=your_generated_secretWebsite Configuration
Section titled “Website Configuration”In general, you can keep the default configurations. If you need to make changes, you can modify the auth config in src/config/website.ts:
export const websiteConfig: WebsiteConfig = { // ... auth: { enable: true, enableGoogleLogin: true, // Whether to enable Google login enableCredentialLogin: true, // Whether to enable email/password login enableDeleteAccount: true, // Whether to support deleting accounts }, // ...};| Option | Type | Default | Description |
|---|---|---|---|
enable |
boolean |
true |
Enable/disable authentication |
enableGoogleLogin |
boolean |
true |
Enable Google OAuth login |
enableCredentialLogin |
boolean |
false |
Enable email/password login |
enableDeleteAccount |
boolean |
true |
Allow users to delete accounts |
Google OAuth (Optional)
Section titled “Google OAuth (Optional)”If Google login is enabled, you need to configure Google OAuth:
- Go to the Google Cloud Console
- Create a new project
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Configure the OAuth consent screen if required
- Select Web application as the application type
- Add
http://localhost:3000andhttps://your-domain.comto Authorized JavaScript origins - Add
http://localhost:3000/api/auth/callback/googleandhttps://your-domain.com/api/auth/callback/googleto Authorized redirect URIs - Add the Client ID and Client Secret to your environment variable file:
.env
GOOGLE_CLIENT_ID=your_google_client_idGOOGLE_CLIENT_SECRET=your_google_client_secretIf you are setting up your environment, you can now return to the Environment Configuration document and continue. The remainder of this document can be read later.
Environment configuration set environment variables
Authentication System Architecture
Section titled “Authentication System Architecture”The authentication system in ShipSaaS consists of the following components:
src
auth/auth.tsclient.tstypes.ts
components/routes/middlewares/
Authentication Routes
Section titled “Authentication Routes”ShipSaaS provides the following authentication routes:
| Route | Description |
|---|---|
/auth/login |
Login page |
/auth/register |
Registration page |
/auth/forgot-password |
Password reset request |
/auth/reset-password |
Password reset form |
/auth/error |
Error page |
References
Section titled “References”Next Steps
Section titled “Next Steps”Now that you understand how authentication works in ShipSaaS, you may want to explore these related features: