# Auth

Authentication and user sync

Source: https://keyenv.dev/docs/api/auth/

Authentication and user sync

## Sync user from Clerk

```http
POST /api/v1/auth/sync
```

Syncs user data from Clerk to KeyEnv. This should be called after a user signs up
or logs in to ensure their account exists in KeyEnv. Creates a personal team for
new users.

**Operation ID:** `authSync` &middot; **Authentication:** `Authorization: Bearer <token>`

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | User synced successfully | `User` |
| `401` | Authentication required | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string (uuid)` |  |
| `clerk_id` | `string` |  |
| `email` | `string (email)` |  |
| `name` | `string` |  |
| `avatar_url` | `string (uri)` |  |
| `auth_type` | `enum (user, service_token)` | Authentication type. Only present for service token auth. |
| `team_id` | `string (uuid)` | Team ID. Only present for service token auth. |
| `project_ids` | `string (uuid)[]` | Project IDs the token has access to. Only present for service token auth. Tokens can access multiple projects. |
| `scopes` | `string[]` | Token scopes (e.g., read, write). Only present for service token auth. |
| `created_at` | `string (date-time)` |  |

### Example

```bash
curl -X POST "https://api.keyenv.dev/api/v1/auth/sync" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```
