feat(auth): implement role-based access control and user management features
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { auth } from '../../../../auth';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { fetchJson } from '../../../lib/api';
|
||||
import UserAdminClient from './UserAdminClient';
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
username: string;
|
||||
email: string;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
role: string;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export default async function AdminUsersPage() {
|
||||
const session = await auth();
|
||||
if (!session || (session.user as any)?.role !== 'admin') {
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
const users = await fetchJson<User[]>('/api/users');
|
||||
|
||||
return (
|
||||
<main className="p-6 max-w-4xl mx-auto">
|
||||
<h1 className="text-2xl font-bold mb-6">Användarhantering</h1>
|
||||
<UserAdminClient users={users} currentUserId={session.user.id} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user