Skip to main content

🔑 Authentication Guide

To query problem details, list solved states, test code against judge servers, and submit solutions, leetrs requires authentication with LeetCode.com.

leetrs uses session cookies (LEETCODE_SESSION and csrftoken) to authenticate all API requests.


🔒 Interactive Auth (leetrs auth)

Run the interactive authentication command:

leetrs auth

You will see an interactive prompt powered by dialoguer:

🔒 LeetCode Authentication

? How would you like to authenticate?
❯ Paste tokens manually
Extract from Firefox
Extract from Chrome

If you are already logged into LeetCode in Chrome or Firefox, select:

  • Extract from Firefox
  • Extract from Chrome

leetrs uses the rookie crate to decrypt and extract active browser cookies without requiring browser extensions or external helpers.

Prerequisites for Automatic Extraction
  • You must be logged into leetcode.com in the chosen browser.
  • Close the browser if keyrings/databases are locked by exclusive file locks on Linux.

✍️ Option 2: Manual Token Fallback

If you are using containerized browsers (Snap / Flatpak), custom profile paths, Brave, Arc, or a headless server:

  1. Select Paste tokens manually.
  2. Open leetcode.com in your browser and open Developer Tools (F12 or Cmd+Option+I).
  3. Navigate to Application (Chrome) or Storage (Firefox) → Cookieshttps://leetcode.com.
  4. Copy the values of:
    • LEETCODE_SESSION
    • csrftoken
  5. Paste them into the interactive prompts in leetrs auth.

🔍 Checking Authentication Status (leetrs status)

Verify your active credentials at any time:

leetrs status

Output:

✅ Currently authenticated!
🔑 csrftoken:
d9a8...f102

🔑 LEETCODE_SESSION:
eyJhbGciOi...

Credentials are saved in ~/.config/leetrs/credentials.json (or %APPDATA%\leetrs\credentials.json on Windows).