add client/admin pages, show info and created admin api and server actions

This commit is contained in:
2024-04-28 19:32:31 +03:00
parent db66161d81
commit d6b259d71c
33 changed files with 458 additions and 91 deletions

View File

@@ -1,4 +1,4 @@
import NextAuth from 'next-auth'
import NextAuth, { type DefaultSession } from 'next-auth'
import { UserRole } from '@prisma/client'
import { PrismaAdapter } from '@auth/prisma-adapter'
import db from '@/lib/db'
@@ -9,9 +9,16 @@ import { getCurrentLocale } from '@/locales/server'
import { type loc } from '@/config/locales'
import { getTwoFactorConfirmationByUserId } from '@/data/two-factor-confirmation'
export type ExtendedUser = DefaultSession['user'] & {
role: UserRole,
locale: loc,
isTwoFactorEnabled?: boolean,
image?: string
}
declare module 'next-auth' {
interface Session {
user: { role: UserRole, locale: loc, image?: string }
user: ExtendedUser
}
}
@@ -67,6 +74,10 @@ export const {
session.user.role = token.role as UserRole
}
if (session.user) {
session.user.isTwoFactorEnabled = token.isTwoFactorEnabled as boolean
}
session.user.locale = getCurrentLocale()
return session
@@ -79,6 +90,7 @@ export const {
if (!existingUser) return token
token.role = existingUser.role
token.isTwoFactorEnabled = existingUser.isTwoFactorEnabled
return token
},