Add example project
This commit is contained in:
parent
20b12f3c60
commit
db9e65e9d7
18 changed files with 4650 additions and 0 deletions
52
example/README.md
Normal file
52
example/README.md
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# 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:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Copy the environment template:
|
||||
|
||||
```bash
|
||||
cp .env.example backend/.env
|
||||
```
|
||||
|
||||
Set `TAUTH_PRIVATE_KEY` in `backend/.env`. Generate keys with:
|
||||
|
||||
```bash
|
||||
pnpm --filter @tauth-example/backend exec cargo run --bin generate_keys
|
||||
```
|
||||
|
||||
For local callback testing, `TAUTH_REDIRECT_URL` must be reachable by TAuth. Use a tunnel if needed.
|
||||
|
||||
## Run
|
||||
|
||||
Run frontend and backend together:
|
||||
|
||||
```bash
|
||||
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.
|
||||
Loading…
Reference in a new issue