Skip to content

feat: Multi-account support and auth exit fix#4

Merged
shahariaazam merged 2 commits intomainfrom
multi-account
Nov 6, 2025
Merged

feat: Multi-account support and auth exit fix#4
shahariaazam merged 2 commits intomainfrom
multi-account

Conversation

@shahariaazam
Copy link
Copy Markdown
Member

Summary

Implements multi-account support allowing users to authenticate and manage multiple Google accounts, plus fixes the auth login hanging issue.

Issues Fixed

Auth login no longer hangs - Command exits immediately after successful authentication
Multi-account support - Manage multiple Google accounts seamlessly

New Features

Multi-Account Management

  • Authenticate with multiple Google accounts
  • Each account identified by email (auto-detected)
  • Set default account for commands
  • Switch between accounts with --account flag
  • List all authenticated accounts
  • Remove specific accounts

New Commands

  • gscli auth list - List all authenticated accounts
  • gscli auth set-default <email> - Set default account
  • gscli auth remove <email> - Remove specific account

Global --account Flag

All commands now support --account <email> option:

  • gscli gmail list --account work@company.com
  • gscli drive list --account personal@gmail.com
  • gscli calendar list --account other@example.com

Usage Examples

# Login with first account
gscli auth login --client ./client.json
# ✅ Authenticated as: user@gmail.com

# Login with second account
gscli auth login --client ./client.json
# (authenticate with different account in browser)
# ✅ Authenticated as: work@company.com

# List all accounts
gscli auth list
# 1. user@gmail.com (default)
# 2. work@company.com

# Set default
gscli auth set-default work@company.com

# Use default account
gscli gmail list

# Use specific account
gscli gmail list --account user@gmail.com
gscli drive list --account work@company.com
gscli calendar list --account personal@example.com

# Remove account
gscli auth remove user@gmail.com

# Logout all
gscli auth logout

Technical Changes

Authentication Flow Fix

  • Clear timeout before closing server
  • Use server.close(callback) for proper shutdown
  • Command exits immediately after success

Multi-Account System

  • New accounts.ts module for account management
  • Store accounts in ~/.config/gscli/accounts.json
  • Added userinfo.email scope to fetch user email
  • Email auto-detected via Google OAuth2 API
  • Client credentials stored per account

Account Storage

{
  "default_account": "user@gmail.com",
  "accounts": {
    "user@gmail.com": {
      "email": "user@gmail.com",
      "client_id": "...",
      "client_secret": "...",
      "access_token": "...",
      "refresh_token": "...",
      "scope": "...",
      "token_type": "Bearer",
      "expiry_date": 123456789
    }
  }
}

Updated All Commands

  • Gmail: list, search, folders-list
  • Drive: list, search, download
  • Calendar: list, search
    All support --account <email> flag

Testing

  • ✅ TypeScript compilation passes
  • ✅ Auth exits properly (no hang)
  • ✅ Multi-account authentication tested
  • ✅ Account switching tested
  • ✅ Default account logic tested
  • ✅ All commands work with --account flag

Breaking Changes

None - fully backward compatible

**Multi-Account Support:**
- Store multiple Google accounts with email identification
- Set default account with 'gscli auth set-default <email>'
- Add --account flag to all commands (gmail, drive, calendar)
- New commands: auth list, auth set-default, auth remove
- Credentials stored per account in ~/.config/gscli/accounts.json

**Auth Exit Fix:**
- Clear timeout before closing server
- Use server.close callback to ensure proper shutdown
- Command now exits immediately after authentication

**Account Management Commands:**
- gscli auth list - Show all authenticated accounts
- gscli auth set-default <email> - Set default account
- gscli auth remove <email> - Remove specific account
- gscli auth logout - Remove all accounts

**Usage:**
- gscli gmail list --account user@example.com
- gscli drive list --account work@company.com
- gscli calendar list (uses default account)

**Storage:**
- All accounts in: ~/.config/gscli/accounts.json
- Automatic user email detection via Google OAuth2 API
- Client credentials saved per account
- Add userinfo.email scope to fetch user email during auth
- Improve getUserEmail error messages with detailed API responses
- Better error handling in accounts.ts
@shahariaazam shahariaazam merged commit 8c30803 into main Nov 6, 2025
1 check passed
@shahariaazam shahariaazam deleted the multi-account branch November 6, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant