BE-5: Implement Google OAuth Authentication and User Management
Description
Implement Google OAuth authentication using Supabase Authentication to allow users to securely sign in to the Multi-Turn AI Chatbot. Configure the complete authentication flow, including Google login, session management, protected API access, user profile creation, and logout functionality.
This issue establishes the application's authentication layer. After successful login, authenticated users should have their profile created (or retrieved) in the database and be able to access protected chatbot features in subsequent development tasks.
User Story
Given that a user wants to access the chatbot
When the user signs in using their Google account
Then the application should authenticate the user, create or retrieve their profile, establish a secure session, and allow access to protected chatbot functionality.
Tasks
1. Configure Google OAuth
2. Configure Supabase Authentication
3. Configure Environment Variables
Add authentication-related configuration.
Example
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
NEXT_PUBLIC_SITE_URL=http://localhost:3000
4. Create Authentication Service
Create a reusable authentication service.
Tasks
Example
services/
auth.service.ts
5. Implement Google Login
Develop Google Sign-In functionality.
6. Create User Profile Management
After successful authentication:
Fields
7. Session Management
Configure authentication sessions.
8. Protect Backend API Routes
Ensure only authenticated users can access protected APIs.
Example response
{
"success": false,
"message": "Unauthorized"
}
9. Create Authentication API Endpoints
Prepare authentication-related endpoints.
Examples
GET /api/auth/session
POST /api/auth/logout
GET /api/auth/user
Tasks
10. Handle Authentication Errors
Implement proper error handling.
11. Verify User Persistence
Ensure authenticated users are correctly stored.
12. Security Validation
13. Documentation
Acceptance Criteria
Testing Steps
- Configure Google OAuth credentials.
- Configure Supabase Authentication.
- Start the Next.js application.
- Click "Sign in with Google."
- Authenticate with a Google account.
- Verify successful redirection.
- Verify a user record is created in Supabase.
- Sign out.
- Verify the session is removed.
- Attempt to access a protected API without authentication.
- Verify an Unauthorized response is returned.
- Sign in again and verify the existing user profile is reused.
- Confirm no duplicate user records are created.
Definition of Done
BE-5: Implement Google OAuth Authentication and User Management
Description
Implement Google OAuth authentication using Supabase Authentication to allow users to securely sign in to the Multi-Turn AI Chatbot. Configure the complete authentication flow, including Google login, session management, protected API access, user profile creation, and logout functionality.
This issue establishes the application's authentication layer. After successful login, authenticated users should have their profile created (or retrieved) in the database and be able to access protected chatbot features in subsequent development tasks.
User Story
Given that a user wants to access the chatbot
When the user signs in using their Google account
Then the application should authenticate the user, create or retrieve their profile, establish a secure session, and allow access to protected chatbot functionality.
Tasks
1. Configure Google OAuth
2. Configure Supabase Authentication
3. Configure Environment Variables
Add authentication-related configuration.
Example
4. Create Authentication Service
Create a reusable authentication service.
Tasks
Example
5. Implement Google Login
Develop Google Sign-In functionality.
6. Create User Profile Management
After successful authentication:
Fields
7. Session Management
Configure authentication sessions.
8. Protect Backend API Routes
Ensure only authenticated users can access protected APIs.
Example response
{ "success": false, "message": "Unauthorized" }9. Create Authentication API Endpoints
Prepare authentication-related endpoints.
Examples
Tasks
10. Handle Authentication Errors
Implement proper error handling.
11. Verify User Persistence
Ensure authenticated users are correctly stored.
12. Security Validation
13. Documentation
Acceptance Criteria
Testing Steps
Definition of Done