Skip to content

Commit 784dca4

Browse files
committed
refactor: API endpoints
1 parent d6100db commit 784dca4

33 files changed

+155
-127
lines changed

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ npx nuxt-users create-user user@example.com "John Doe" password123
110110
- **Table management**: Utilities for checking table existence and managing database schema
111111

112112
### API Routes
113-
- **`/api/auth/login`**: POST endpoint for user authentication with bcrypt password verification and token generation
114-
- **`/api/auth/forgot-password`**: POST endpoint for password reset initiation
115-
- **`/api/auth/reset-password`**: POST endpoint for password reset completion
113+
- **`/api/nuxt-users/session`**: POST login, DELETE logout
114+
- **`/api/nuxt-users/password/forgot`**: POST password reset initiation
115+
- **`/api/nuxt-users/password/reset`**: POST password reset completion
116116

117117
### Vue Components
118118
- **LoginForm**: User authentication and forgot password form
@@ -216,7 +216,7 @@ yarn docs:deploy
216216
- **Database utilities**: `src/utils/db.ts:28` (useDb function)
217217
- **CLI entry**: `src/cli/main.ts:11` (command definitions)
218218
- **Type definitions**: `src/types.ts:11` (ModuleOptions interface)
219-
- **Login API**: `src/runtime/server/api/auth/login.post.ts:8` (authentication handler)
219+
- **Login API**: `src/runtime/server/api/nuxt-users/session/index.post.ts:8` (authentication handler)
220220

221221
## Documentation Mapping
222222

docs/api/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Nuxt Users module provides several API endpoints for authentication, user ma
66

77
### Login
88

9-
**Endpoint:** `POST /api/auth/login`
9+
**Endpoint:** `POST /api/nuxt-users/session`
1010

1111
Authenticate a user with email and password.
1212

@@ -38,7 +38,7 @@ Authenticate a user with email and password.
3838

3939
### Logout
4040

41-
**Endpoint:** `GET /api/auth/logout`
41+
**Endpoint:** `DELETE /api/nuxt-users/session`
4242

4343
Logout the current user by removing their authentication token.
4444

@@ -181,7 +181,7 @@ Delete a user.
181181

182182
### Get Profile
183183

184-
**Endpoint:** `GET /api/nuxt-users/profile`
184+
**Endpoint:** `GET /api/nuxt-users/me`
185185

186186
Get the current user's profile information.
187187

@@ -206,7 +206,7 @@ Get the current user's profile information.
206206

207207
### Update Password
208208

209-
**Endpoint:** `POST /api/auth/update-password`
209+
**Endpoint:** `PATCH /api/nuxt-users/password`
210210

211211
Update the current user's password.
212212

@@ -240,7 +240,7 @@ Update the current user's password.
240240

241241
### Forgot Password
242242

243-
**Endpoint:** `POST /api/auth/forgot-password`
243+
**Endpoint:** `POST /api/nuxt-users/password/forgot`
244244

245245
Send a password reset link to the user's email.
246246

@@ -265,7 +265,7 @@ Send a password reset link to the user's email.
265265

266266
### Reset Password
267267

268-
**Endpoint:** `POST /api/auth/reset-password`
268+
**Endpoint:** `POST /api/nuxt-users/password/reset`
269269

270270
Reset user password using a valid token.
271271

@@ -323,9 +323,9 @@ The user management endpoints use a role-based permission system:
323323

324324
Consider implementing rate limiting for these endpoints:
325325

326-
- `/api/auth/login`: Prevent brute force attacks
327-
- `/api/auth/forgot-password`: Prevent email spam
328-
- `/api/auth/reset-password`: Prevent token brute force
326+
- `/api/nuxt-users/session`: Prevent brute force attacks
327+
- `/api/nuxt-users/password/forgot`: Prevent email spam
328+
- `/api/nuxt-users/password/reset`: Prevent token brute force
329329
- `/api/nuxt-users/*`: Prevent abuse of user management endpoints
330330

331331
## Next Steps

docs/api/types-and-utilities.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ getCurrentUserFromToken<T extends boolean = false>(
192192

193193
**Example:**
194194
```typescript
195-
// server/api/user/profile.get.ts
195+
// server/api/nuxt-users/me.get.ts
196196
export default defineEventHandler(async (event) => {
197197
const token = getCookie(event, 'auth_token')
198198

@@ -271,7 +271,7 @@ if (!result.isValid) {
271271
Create a comprehensive user profile API:
272272

273273
```typescript
274-
// server/api/user/profile-complete.get.ts
274+
// server/api/nuxt-users/me-complete.get.ts
275275
import { getCurrentUserFromToken, getLastLoginTime } from 'nuxt-users/utils'
276276
import type { UserWithoutPassword } from 'nuxt-users/utils'
277277

docs/components/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const handleError = (error) => {
4141

4242
| Prop | Type | Default | Description |
4343
|------|------|---------|-------------|
44-
| `apiEndpoint` | `string` | `'/api/auth/login'` | The API endpoint for login requests |
44+
| `apiEndpoint` | `string` | `'/api/nuxt-users/session'` | The API endpoint for login requests |
4545
| `redirectTo` | `string` | `'/'` | Where to redirect after successful login |
4646

4747
### Events
@@ -299,7 +299,7 @@ This component handles its own API calls, message display, and redirection to lo
299299

300300
- Automatically reads `token` and `email` from URL query parameters
301301
- Password confirmation validation
302-
- API calls to `/api/auth/reset-password`
302+
- API calls to `/api/nuxt-users/password/reset`
303303
- Automatic redirection to login on success
304304
- Error handling and display
305305

docs/contributing/code-style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ interface Emits {
7777
}
7878
7979
const props = withDefaults(defineProps<Props>(), {
80-
apiEndpoint: '/api/auth/login',
80+
apiEndpoint: '/api/nuxt-users/session',
8181
redirectTo: '/'
8282
})
8383

docs/contributing/running-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('Login API', () => {
253253
})
254254

255255
it('should login successfully', async () => {
256-
const response = await $fetch('/api/auth/login', {
256+
const response = await $fetch('/api/nuxt-users/session', {
257257
method: 'POST',
258258
body: {
259259
email: 'test@example.com',

docs/guide/authentication.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineNuxtConfig({
3030

3131
## Authentication Flow
3232

33-
Upon successful login via the `/api/auth/login` endpoint:
33+
Upon successful login via the `/api/nuxt-users/session` endpoint:
3434

3535
1. **User submits credentials** - Email and password are sent to the server
3636
2. **Password verification** - bcrypt compares the password with the stored hash
@@ -75,7 +75,7 @@ CREATE TABLE personal_access_tokens (
7575

7676
### Endpoint
7777

78-
`POST /api/auth/login`
78+
`POST /api/nuxt-users/session`
7979

8080
### Request Body
8181

@@ -149,7 +149,7 @@ You can implement custom login logic:
149149
<script setup>
150150
const login = async (email, password) => {
151151
try {
152-
const response = await $fetch('/api/auth/login', {
152+
const response = await $fetch('/api/nuxt-users/session', {
153153
method: 'POST',
154154
body: { email, password }
155155
})
@@ -256,9 +256,7 @@ You can also call the logout API directly:
256256
<script setup>
257257
const logout = async () => {
258258
try {
259-
await $fetch('/api/auth/logout', {
260-
method: 'GET'
261-
})
259+
await $fetch('/api/nuxt-users/session', { method: 'DELETE' })
262260
console.log('Logged out successfully')
263261
} catch (error) {
264262
console.error('Logout failed:', error)
@@ -409,9 +407,9 @@ export default defineNuxtConfig({
409407
banDuration: 300000, // 5 minute ban for violators
410408
delay: 1000, // 1 second delay on banned IPs
411409
routes: [
412-
'/api/auth/login', // Protect login endpoint
413-
'/api/auth/forgot-password', // Protect password reset requests
414-
'/api/auth/reset-password' // Protect password reset completion
410+
'/api/nuxt-users/session', // Protect login endpoint
411+
'/api/nuxt-users/password/forgot', // Protect password reset requests
412+
'/api/nuxt-users/password/reset' // Protect password reset completion
415413
],
416414
log: true // Enable logging for monitoring
417415
}
@@ -432,12 +430,12 @@ For different security levels on different endpoints:
432430
```ts
433431
apiShield: {
434432
routes: {
435-
'/api/auth/login': {
433+
'/api/nuxt-users/session': {
436434
maxRequests: 5, // Stricter limit for login
437435
duration: 60000, // 1 minute
438436
banDuration: 600000 // 10 minute ban
439437
},
440-
'/api/auth/forgot-password': {
438+
'/api/nuxt-users/password/forgot': {
441439
maxRequests: 3, // Very strict for password reset
442440
duration: 300000, // 5 minute window
443441
banDuration: 1800000 // 30 minute ban

docs/guide/authorization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineNuxtConfig({
3434
whitelist: ['/login', '/register', '/public'],
3535
permissions: {
3636
admin: ['*'], // Admin can access everything
37-
user: ['/profile', '/settings', '/api/user/profile'],
37+
user: ['/profile', '/settings', '/api/nuxt-users/me'],
3838
moderator: ['/admin/*', '/api/admin/*', '/moderate/*'],
3939
editor: ['/editor/*', '/api/editor/*', '/content/*']
4040
}
@@ -50,7 +50,7 @@ The system supports various pattern matching for flexible route protection:
5050
#### Exact Paths
5151
```ts
5252
permissions: {
53-
user: ['/profile', '/settings']
53+
user: ['/profile', '/settings']
5454
}
5555
```
5656

@@ -66,7 +66,7 @@ permissions: {
6666
#### Complex Wildcards
6767
```ts
6868
permissions: {
69-
api_user: ['/api/*/profile'], // Access to profile endpoints under any API section
69+
api_user: ['/api/*/profile'], // Example pattern
7070
manager: ['/admin/*/users/*'] // Access to user management under admin
7171
}
7272
```
@@ -95,7 +95,7 @@ nuxtUsers: {
9595
permissions: {
9696
admin: ['*'],
9797
manager: ['/admin/*', '/api/admin/*', '/reports/*'],
98-
customer: ['/profile', '/orders', '/api/user/*'],
98+
customer: ['/profile', '/orders', '/api/nuxt-users/*'],
9999
vendor: ['/vendor/*', '/api/vendor/*', '/products/manage']
100100
}
101101
}

docs/guide/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ nuxtUsers: {
317317
tokenExpiration: 1440, // Token expiration in minutes (default: 24 hours)
318318
permissions: {
319319
admin: ['*'], // Admin can access everything
320-
user: ['/profile', '/settings', '/api/user/profile'],
320+
user: ['/profile', '/settings', '/api/nuxt-users/me'],
321321
moderator: ['/admin/*', '/api/admin/*']
322322
}
323323
}
@@ -439,7 +439,7 @@ export default defineNuxtConfig({
439439
maxRequests: 5,
440440
duration: 60000,
441441
banDuration: 300000,
442-
routes: ['/api/auth/login', '/api/auth/forgot-password']
442+
routes: ['/api/nuxt-users/session', '/api/nuxt-users/password/forgot']
443443
}
444444
})
445445
```

docs/guide/password-reset.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ This component provides a form for users to set a new password using a token fro
101101

102102
The component:
103103
- Automatically reads `token` and `email` from URL query parameters
104-
- Handles API calls to `/api/auth/reset-password`
104+
- Handles API calls to `/api/nuxt-users/password/reset`
105105
- Validates password confirmation
106106
- Redirects to login upon success
107107

108108
## API Endpoints
109109

110110
### Forgot Password
111111

112-
**Endpoint:** `POST /api/auth/forgot-password`
112+
**Endpoint:** `POST /api/nuxt-users/password/forgot`
113113

114114
**Request Body:**
115115
```json
@@ -127,7 +127,7 @@ The component:
127127

128128
### Reset Password
129129

130-
**Endpoint:** `POST /api/auth/reset-password`
130+
**Endpoint:** `POST /api/nuxt-users/password/reset`
131131

132132
**Request Body:**
133133
```json
@@ -154,7 +154,7 @@ The component:
154154
<script setup>
155155
const requestReset = async (email) => {
156156
try {
157-
await $fetch('/api/auth/forgot-password', {
157+
await $fetch('/api/nuxt-users/password/forgot', {
158158
method: 'POST',
159159
body: { email }
160160
})
@@ -176,7 +176,7 @@ const requestReset = async (email) => {
176176
<script setup>
177177
const resetPassword = async (token, email, password, passwordConfirmation) => {
178178
try {
179-
await $fetch('/api/auth/reset-password', {
179+
await $fetch('/api/nuxt-users/password/reset', {
180180
method: 'POST',
181181
body: {
182182
token,

0 commit comments

Comments
 (0)