add client/admin pages, show info and created admin api and server actions
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
@@ -37,4 +37,6 @@ const LC: Locale[] = [
|
||||
|
||||
const locales: loc[] = LC.map((locale: Locale) => locale.code)
|
||||
|
||||
export { locales, defaultLocale, fallbackLocale, LC, importLocales, type loc }
|
||||
const SKIP_I18N_URLS = '/api/'
|
||||
|
||||
export { locales, defaultLocale, fallbackLocale, LC, importLocales, type loc, SKIP_I18N_URLS }
|
||||
@@ -1,6 +1,9 @@
|
||||
import { UUID_V4_REGEX } from '@/config/validation'
|
||||
|
||||
export const USER_PROFILE_URL: string = '/cabinet'
|
||||
export const USER_SERVER_URL: string = `${USER_PROFILE_URL}/server`
|
||||
export const USER_CLIENT_URL: string = `${USER_PROFILE_URL}/client`
|
||||
export const USER_ADMIN_URL: string = `${USER_PROFILE_URL}/admin`
|
||||
export const AUTH_URL: string = '/auth/'
|
||||
export const AUTH_LOGIN_URL: string = `${AUTH_URL}login`
|
||||
export const AUTH_REGISTER_URL: string = `${AUTH_URL}register`
|
||||
@@ -9,6 +12,8 @@ export const AUTH_ERROR_URL: string = `${AUTH_URL}error`
|
||||
export const AUTH_USER_VERIFICATION_URL: string = `${AUTH_URL}user-verification`
|
||||
export const AUTH_NEW_PASSWORD_URL: string = `${AUTH_URL}new-password`
|
||||
|
||||
export const CABINET_ROUTES: string[] = [USER_SERVER_URL, USER_CLIENT_URL, USER_ADMIN_URL, USER_PROFILE_URL] as const
|
||||
|
||||
/**
|
||||
* An array of routes that accessible to the public.
|
||||
* These routes do not requite authentication.
|
||||
@@ -31,10 +36,10 @@ export const authRoutesRegEx = [
|
||||
|
||||
/**
|
||||
* The prefix for API authentication routes.
|
||||
* Routes that start with this prefix are used for API authentication purpose.
|
||||
* Routes that start with this prefix are used for API authentication purposes.
|
||||
* @type {string}
|
||||
*/
|
||||
export const apiAuthPrefix: string = '/api/auth'
|
||||
export const apiAuthPrefixRegEx: string = '/api/(auth|admin)'
|
||||
|
||||
/**
|
||||
* The default redirect path after logging in.
|
||||
|
||||
Reference in New Issue
Block a user