feat(auth): implement role-based access control and user management features

This commit is contained in:
Nils-Johan Gynther
2026-04-18 09:34:22 +02:00
parent 20330f6410
commit c5ccef2313
22 changed files with 358 additions and 10 deletions
+4 -1
View File
@@ -22,11 +22,12 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
}),
});
if (!res.ok) return null;
const data = await res.json() as { accessToken: string; userId: number; username: string };
const data = await res.json() as { accessToken: string; userId: number; username: string; role: string };
return {
id: String(data.userId),
name: data.username,
accessToken: data.accessToken,
role: data.role,
};
} catch {
return null;
@@ -40,6 +41,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
token.accessToken = (user as any).accessToken as string;
token.userId = Number(user.id);
token.username = user.name ?? '';
token.role = (user as any).role as string;
}
return token;
},
@@ -47,6 +49,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
session.accessToken = token.accessToken as string;
session.user.id = String(token.userId);
session.user.name = token.username as string;
(session.user as any).role = token.role as string;
return session;
},
},