fix: adjust admin user routes and sidebar deps

This commit is contained in:
Esdras Renan 2025-10-13 11:59:09 -03:00
parent 4951e82834
commit 076c0df7f9
3 changed files with 10 additions and 7 deletions

View file

@ -17,14 +17,15 @@ function generatePassword(length = 12) {
export const runtime = "nodejs" export const runtime = "nodejs"
export async function POST(request: Request, { params }: { params: { id: string } }) { export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const session = await assertAdminSession() const session = await assertAdminSession()
if (!session) { if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 }) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
} }
const user = await prisma.authUser.findUnique({ const user = await prisma.authUser.findUnique({
where: { id: params.id }, where: { id },
select: { id: true, role: true }, select: { id: true, role: true },
}) })

View file

@ -22,14 +22,15 @@ function mapToUserRole(role: RoleOption) {
export const runtime = "nodejs" export const runtime = "nodejs"
export async function GET(_: Request, { params }: { params: { id: string } }) { export async function GET(_: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const session = await assertAdminSession() const session = await assertAdminSession()
if (!session) { if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 }) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
} }
const user = await prisma.authUser.findUnique({ const user = await prisma.authUser.findUnique({
where: { id: params.id }, where: { id },
select: { select: {
id: true, id: true,
email: true, email: true,
@ -70,7 +71,8 @@ export async function GET(_: Request, { params }: { params: { id: string } }) {
}) })
} }
export async function PATCH(request: Request, { params }: { params: { id: string } }) { export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const session = await assertAdminSession() const session = await assertAdminSession()
if (!session) { if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 }) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
@ -88,7 +90,7 @@ export async function PATCH(request: Request, { params }: { params: { id: string
return NextResponse.json({ error: "Payload inválido" }, { status: 400 }) return NextResponse.json({ error: "Payload inválido" }, { status: 400 })
} }
const user = await prisma.authUser.findUnique({ where: { id: params.id } }) const user = await prisma.authUser.findUnique({ where: { id } })
if (!user) { if (!user) {
return NextResponse.json({ error: "Usuário não encontrado" }, { status: 404 }) return NextResponse.json({ error: "Usuário não encontrado" }, { status: 404 })
} }

View file

@ -133,7 +133,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
}) })
}) })
return open return open
}, [pathname]) }, [pathname, canAccess])
const [expanded, setExpanded] = React.useState<Set<string>>(initialExpanded) const [expanded, setExpanded] = React.useState<Set<string>>(initialExpanded)
React.useEffect(() => { React.useEffect(() => {