add auth
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { getLibrary } from '@/lib/libraries'
|
||||
import { notFound } from 'next/navigation'
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import { getServerSession } from '@/lib/auth'
|
||||
import { getPermittedLibraryIds } from '@/lib/users'
|
||||
import GamesView from '@/components/games/GamesView'
|
||||
import MixedView from '@/components/mixed/MixedView'
|
||||
import MoviesView from '@/components/movies/MoviesView'
|
||||
@@ -14,9 +16,17 @@ export default async function LibraryPage({ params, searchParams }: Props) {
|
||||
const { id } = await params
|
||||
const { path: subpath } = await searchParams
|
||||
|
||||
const session = await getServerSession()
|
||||
if (!session.userId) redirect('/login')
|
||||
|
||||
const library = getLibrary(id)
|
||||
if (!library) notFound()
|
||||
|
||||
if (session.role !== 'admin') {
|
||||
const permitted = getPermittedLibraryIds(session.userId)
|
||||
if (!permitted.includes(id)) notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
|
||||
Reference in New Issue
Block a user