feat: auth & admin

This commit is contained in:
2026-06-03 10:41:53 +03:00
parent 612d0f0125
commit 7dc59fb3c4
120 changed files with 4683 additions and 2159 deletions
@@ -12,46 +12,47 @@ Use Next.js's `after()` to schedule work that should execute after a response is
**Incorrect (blocks response):**
```tsx
import { logUserAction } from '@/app/utils'
import { logUserAction } from '@/app/utils';
export async function POST(request: Request) {
// Perform mutation
await updateDatabase(request)
await updateDatabase(request);
// Logging blocks the response
const userAgent = request.headers.get('user-agent') || 'unknown'
await logUserAction({ userAgent })
const userAgent = request.headers.get('user-agent') || 'unknown';
await logUserAction({ userAgent });
return new Response(JSON.stringify({ status: 'success' }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
})
headers: { 'Content-Type': 'application/json' },
});
}
```
**Correct (non-blocking):**
```tsx
import { after } from 'next/server'
import { headers, cookies } from 'next/headers'
import { logUserAction } from '@/app/utils'
import { after } from 'next/server';
import { headers, cookies } from 'next/headers';
import { logUserAction } from '@/app/utils';
export async function POST(request: Request) {
// Perform mutation
await updateDatabase(request)
await updateDatabase(request);
// Log after response is sent
after(async () => {
const userAgent = (await headers()).get('user-agent') || 'unknown'
const sessionCookie = (await cookies()).get('session-id')?.value || 'anonymous'
logUserAction({ sessionCookie, userAgent })
})
const userAgent = (await headers()).get('user-agent') || 'unknown';
const sessionCookie =
(await cookies()).get('session-id')?.value || 'anonymous';
logUserAction({ sessionCookie, userAgent });
});
return new Response(JSON.stringify({ status: 'success' }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
})
headers: { 'Content-Type': 'application/json' },
});
}
```