Google OAuth Integration¶
Atlas ERP supports Single Sign-On (SSO) via Google, allowing users to log in quickly without creating a new password. This is powered by Better Auth's social provider plugins.
Configuration Steps¶
1. Create Google Cloud Project¶
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services > Credentials.
2. Configure OAuth Consent Screen¶
- Go to the OAuth consent screen tab.
- Choose External (unless you are restricting it to your specific Google Workspace organization).
- Fill in the App name, Support email, and Developer contact information.
- Add the necessary scopes:
.../auth/userinfo.emailand.../auth/userinfo.profile.
3. Create Credentials¶
- Go back to the Credentials tab.
- Click Create Credentials -> OAuth client ID.
- Application type: Web application.
- Name: e.g., "Atlas ERP Auth".
- Authorized JavaScript origins: Add your frontend URL (e.g.,
http://localhost:3000,https://app.yourdomain.com). - Authorized redirect URIs: Add the Better Auth callback URL.
- Local:
http://localhost:3000/auth/callback(or wherever your frontend handles the redirect before sending it to the API). - Note: Better Auth usually handles the callback on the API side directly at
/api/v1/auth/callback/googledepending on your setup.
4. Set Environment Variables¶
Copy the Client ID and Client Secret generated by Google and add them to apps/api/.env:
| Bash | |
|---|---|
Testing Locally¶
Ensure your GOOGLE_REDIRECT_URI matches exactly what you configured in the Google Cloud Console. When a user clicks "Sign in with Google" on the frontend, they will be redirected to Google, and upon success, redirected back to your app with a session token.