Skip to content

Implement Google OAuth Authentication for LogiQuestΒ #145

@onlydustapp

Description

@onlydustapp

πŸ“š Overview

Implement Google OAuth authentication in LogiQuest to allow users to sign in with their Google accounts. This feature should leverage Passport.js and work seamlessly within the existing authentication flow.

πŸ› οΈ Tasks

  1. Add Google OAuth Strategy

    • Implement a Google OAuth strategy using Passport.js
    • Create a GoogleStrategy provider
    • Configure authentication using environment variables (ensure documentation is updated)
  2. Create Authentication Controller Endpoints

    • Add an endpoint to initiate Google authentication
    • Create a callback endpoint to handle Google's response
    • Implement user profile creation for new Google users
  3. Update User Entity

    • Add a googleId field
    • Add a provider field (values: local/google)
    • Ensure proper updates to the database schema
  4. JWT Generation for Google Auth

    • Generate JWT tokens after successful Google authentication
    • Ensure proper user data is included in the tokens
  5. HTTPyac Test Files

    • Include HTTPyac test files to demonstrate the working implementation
### Initiate Google Auth (this will redirect to Google)
GET http://localhost:3000/auth/google

### Manually test the callback URL after authentication
GET http://localhost:3000/auth/google/callback?code=EXAMPLE_CODE

### Verify that the JWT token works by accessing a protected endpoint
GET http://localhost:3000/auth/profile
Authorization: Bearer {{google.response.body.access_token}}

🚨 Technical & Setup Considerations

  • Use @nestjs/passport and passport-google-oauth20 packages
  • Use environment variables for Google OAuth credentials (Client ID/Secret)
  • IMPORTANT: Use npm ci instead of npm install when setting up the project to avoid dependency issues

βœ… Acceptance Criteria

  • Users can initiate authentication with Google
  • Google authentication flow completes successfully
  • New users are created on first Google login
  • Existing users are properly linked with Google accounts
  • JWT tokens are issued after successful authentication
  • Error handling for failed authentication attempts
  • Environment variables are documented for Google OAuth credentials

πŸ“„ References

Let's ensure we follow the dependency guidelines and use the proper setup commands πŸ˜ƒ

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions