Auth Login Service

This service provides Google OAuth authentication for your application with a profile collection form.

Test The Authentication Flow

Click the button below to test the authentication flow:

Login with Google

Available Endpoints

GET /login

Redirects the user to Google for authentication.

GET /callback

Handles the OAuth callback from Google. Sets a session cookie and redirects to the profile form if needed.

GET /collect-profile

Displays a form to collect additional user information (name, institution, position).

POST /profile

Accepts form submissions and updates the user profile.

GET /user

Returns the current user's profile information (requires authentication).

GET /logout

Logs the user out by clearing their session cookie.

GET /terms

Displays the Terms and Conditions page.

GET /privacy

Displays the Privacy Policy page.

Integration Guide

To integrate with your application:

  1. Redirect users to /login to begin authentication.
  2. After authentication, users will be redirected to /chat with a session cookie.
  3. Your application should verify the session cookie by fetching user data from KV.

Cookie Format

The service sets a cookie named __hl_session containing a UUID that identifies the user session.

Sample Integration Code

// Check for auth cookie
const uuid = getCookie(request, '__hl_session');
if (!uuid) {
  return Response.redirect('/login', 302);
}

// Verify user exists in KV
const userJson = await env.USERS.get(`user:${uuid}`);
if (!userJson) {
  return Response.redirect('/login', 302);
}

// User is authenticated
const user = JSON.parse(userJson);
// Continue with your application logic