or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

User Authentication Service

Build a user authentication service that allows users to sign in using their Google accounts. The service should provide authentication routes and handle the complete OAuth flow.

Requirements

Your implementation should:

  1. Set up a Google OAuth 2.0 authentication strategy with the following configuration:

    • Client ID from environment variable GOOGLE_CLIENT_ID
    • Client secret from environment variable GOOGLE_CLIENT_SECRET
    • Callback URL pointing to /auth/google/callback
    • Request profile and email scopes
  2. Create two authentication routes:

    • /auth/google - Initiates the Google authentication flow
    • /auth/google/callback - Handles the callback from Google after authentication
  3. After successful authentication, redirect users to /dashboard

  4. After failed authentication, redirect users to /login

  5. Store basic user information (Google ID, display name, and email) in memory during the authentication callback

Test Cases

  • When a user visits /auth/google, the authentication flow is initiated with Google @test
  • When authentication succeeds, the callback handler redirects to /dashboard @test
  • When authentication fails, the callback handler redirects to /login @test

Implementation

@generates

API

/**
 * Configure Google OAuth 2.0 authentication strategy and routes
 * @param {Object} app - Express application instance
 * @param {Object} passport - Passport instance
 * @returns {void}
 */
function setupGoogleAuth(app, passport);

Dependencies { .dependencies }

passport { .dependency }

Authentication middleware for Node.js

passport-google-oauth { .dependency }

Provides Google OAuth authentication strategies for Passport.js

express { .dependency }

Web framework for handling HTTP requests and routes