tauth-sdk/example/README.md

1.5 KiB

TAuth SDK Vite + React Example

This example has a Vite/React frontend and a tiny Rust backend that uses the local tauth-sdk crate.

It demonstrates:

  • creating a TAuth login URL with TAuthClient::auth_url
  • parsing the TAuth callback with TAuthClient::parse_callback
  • fetching the logged-in user's TAuth profile
  • storing the session/user/app data in backend/data/db.json
  • optionally syncing app data through MTP when TAUTH_HOST_PUBLIC_KEY is set

Setup

Install frontend dependencies:

pnpm install

Copy the environment template:

cp .env.example backend/.env

Set TAUTH_PRIVATE_KEY in backend/.env. Generate keys with:

pnpm --filter @tauth-example/backend exec cargo run --bin generate_keys

Publish the generated TAUTH_PUBLIC_KEY_SHA256 value in the tauth.<identifier> TXT record. TAuth receives the full public key during authorization and verifies it against that hash.

For local callback testing, TAUTH_REDIRECT_URL must be reachable by TAuth. Use a tunnel if needed.

Run

Run frontend and backend together:

pnpm dev

Open http://localhost:5173 and click Login with TAuth.

Backend Endpoints

  • GET /api/login: redirects to TAuth
  • GET /tauth/callback: receives TAuth callback and stores the session
  • GET /api/me: returns the current cookie session and cached user data
  • PUT /api/app-data: saves JSON app data locally and optionally through MTP

The JSON database is intentionally simple for example purposes. Do not use it as-is for production.