Skip to content

Commit 86456e6

Browse files
committed
added documentation for auth endpoint
1 parent 375cd6b commit 86456e6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

backend/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ JWT check is toggled based on directory
4141

4242
## 🚀 Endpoint Documentation
4343

44+
### `/auth`
45+
Authenticates a user via Telegram Mini App (TMA) initialization data and issues a short-lived JWT. In development environments, it returns a mock token for testing purposes.
46+
47+
- **Method:** `GET`
48+
- **Auth:** No
49+
- **Headers:** `Authorization`: `tma <raw_init_data>`
50+
- **Success (200 OK):** Returns a signed JWT. `{ "token": "jwt" }`
51+
52+
- **Possible Errors:**
53+
54+
| Code | Error Message | Reason |
55+
|:-----|:-------------------------------|:------------------------------------------------------------------------------|
56+
| 401 | `Unauthorized` | Authorization header is missing or prefix is not `tma`. |
57+
| 500 | `Invalid Telegram auth string` | The init data is malformed or missing required fields like `chat_instance`. |
58+
| 500 | `Expired Telegram auth string` | The `auth_date` provided is older than 12 hours. |
59+
| 500 | `Invalid signature` | The HMAC signature verification failed against the `BOT_TOKEN`. |
60+
| 500 | `Missing hash` | The `hash` parameter is missing from the provided authentication data. |
61+
62+
> **Note:** When `NODE_ENV` is set to `development`, this endpoint returns a token for a default user ID (`2202843044`) without validating headers.
63+
4464
### `/queue/status`
4565
To check if queue is opened or closed.
4666
- **Method:** `GET`

backend/src/queueConfigPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const queueConfigPlugin: FastifyPluginAsync = fp(async (fastify, _) => {
66

77
let cacheConfig: QueueConfigModel | undefined;
88

9+
// QueueConfig should only be accessed through this function to reduce calls to DB
10+
911
// force if true forces a db fetch
1012
let getQueueConfig: (force?: boolean) => Promise<QueueConfigModel> = async (force?: boolean) => {
1113
if (cacheConfig != null && !force) {

0 commit comments

Comments
 (0)