Overview
Budget Bee supports Google OAuth 2.0 authentication, allowing users to sign in with their Google accounts. Google is configured as a trusted provider for account linking.Configuration
Environment Variables
To enable Google OAuth, configure the following environment variables:.env
Google Cloud Console Setup
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API
- Create OAuth 2.0 credentials:
- Application type: Web application
- Authorized redirect URIs:
{NEXT_PUBLIC_APP_URL}/api/auth/callback/google
Make sure to add your production, staging, and local development URLs to the authorized redirect URIs.
OAuth Flow
1. Initiate OAuth
Redirect users to the Google OAuth authorization URL.Query Parameters
Optional redirect URL after successful authentication. Defaults to
/dashboard.Request Example
2. OAuth Callback
After user grants permission, Google redirects back to your application.Query Parameters
Authorization code from Google
State parameter for CSRF protection
What Happens Next
- Budget Bee exchanges the authorization code for an access token
- User information is retrieved from Google
- If user exists, they are signed in
- If new user, an account is created
- User is redirected to the callback URL or dashboard
Account Linking
Google is configured as a trusted provider, which means:- If a user signs up with email/password and later signs in with Google (same email), the accounts are automatically linked
- Users can switch between authentication methods seamlessly
- No duplicate accounts are created
Account Schema
When a user authenticates via Google, an account record is created:Unique account identifier
Google user ID
Always “google” for Google OAuth
Reference to the Budget Bee user
Google OAuth access token (encrypted)
Google OAuth refresh token (encrypted)
Google ID token
When the access token expires
When the refresh token expires
Account creation timestamp
Last update timestamp
OAuth Configuration
Budget Bee’s Google OAuth is configured with the following settings:Prompt Behavior
Scopes
Default scopes requested from Google:openid- OpenID Connect authenticationemail- Access to user’s email addressprofile- Access to user’s basic profile information
Client-Side Integration
React Example
Using the Budget Bee auth client:Redirect Example
Alternatively, use a simple link:Security Features
CSRF Protection
The OAuth flow includes state parameter verification to prevent CSRF attacks.Token Storage
OAuth tokens are:- Encrypted at rest in the database
- Never exposed to the client
- Automatically refreshed when expired
Account Verification
Users authenticating via Google:- Are automatically marked as email verified (if Google account is verified)
- Can immediately access all features
- Can create organizations without additional verification
Common Issues
Redirect URI Mismatch
Error:redirect_uri_mismatch
Solution: Ensure the callback URL in Google Cloud Console exactly matches:
Access Denied
Error:access_denied
Cause: User declined authorization or closed the consent screen.
Solution: This is expected behavior. Users can try again.
Invalid Client
Error:invalid_client
Cause: Google Client ID or Secret is incorrect.
Solution: Verify GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables.
Best Practices
Multiple Environments
Set up separate OAuth credentials for:- Development (localhost)
- Staging
- Production
Error Handling
Always handle OAuth errors gracefully:Privacy Compliance
Inform users about:- What data you access from Google
- How it’s used
- Your privacy policy
Response Examples
Successful Authentication
After successful OAuth, the user is redirected with a session cookie, and subsequent requests to/api/auth/get-session return:

