File size: 2,855 Bytes
07af8f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: "Authentication"
description: "Manage users and authentication."
---

import { Card, Cards } from 'mintlify';

<Card
  title="POST /api/auth/login"
  href="#login"
>
  Log in to get a JWT token.
</Card>

<Card
  title="POST /api/auth/register"
  href="#register"
>
  Register a new user.
</Card>

<Card
  title="GET /api/auth/user"
  href="#get-current-user"
>
  Get the currently authenticated user.
</Card>

<Card
  title="POST /api/auth/change-password"
  href="#change-password"
>
  Change the password for the current user.
</Card>

---

### Login

Authenticates a user and returns a JWT token along with user details.

- **Endpoint**: `/api/auth/login`
- **Method**: `POST`
- **Body**:
  - `username` (string, required): The user's username.
  - `password` (string, required): The user's password.
- **Request Example**:
  ```json
  {
    "username": "admin",
    "password": "admin123"
  }
  ```
- **Success Response**:
  ```json
  {
    "success": true,
    "message": "Login successful",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "user": {
      "username": "admin",
      "isAdmin": true,
      "permissions": { ... }
    }
  }
  ```

---

### Register

Registers a new user and returns a JWT token.

- **Endpoint**: `/api/auth/register`
- **Method**: `POST`
- **Body**:
  - `username` (string, required): The desired username.
  - `password` (string, required): The desired password (must be at least 6 characters).
  - `isAdmin` (boolean, optional): Whether the user should have admin privileges.
- **Request Example**:
  ```json
  {
    "username": "newuser",
    "password": "password123",
    "isAdmin": false
  }
  ```
- **Success Response**:
  ```json
  {
    "success": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "user": {
      "username": "newuser",
      "isAdmin": false,
      "permissions": { ... }
    }
  }
  ```

---

### Get Current User

Retrieves the profile of the currently authenticated user.

- **Endpoint**: `/api/auth/user`
- **Method**: `GET`
- **Authentication**: Bearer Token required.
- **Success Response**:
  ```json
  {
    "success": true,
    "user": {
      "username": "admin",
      "isAdmin": true,
      "permissions": { ... }
    }
  }
  ```

---

### Change Password

Allows the authenticated user to change their password.

- **Endpoint**: `/api/auth/change-password`
- **Method**: `POST`
- **Authentication**: Bearer Token required.
- **Body**:
  - `currentPassword` (string, required): The user's current password.
  - `newPassword` (string, required): The desired new password (must be at least 6 characters).
- **Request Example**:
  ```json
  {
    "currentPassword": "oldpassword",
    "newPassword": "newpassword123"
  }
  ```
- **Success Response**:
  ```json
  {
    "success": true,
    "message": "Password updated successfully"
  }
  ```