-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update roles on dashboard, fix auth
- Loading branch information
1 parent
67f0aeb
commit 46bec95
Showing
19 changed files
with
390 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,4 +278,4 @@ const Register: React.FC = () => { | |
); | ||
}; | ||
|
||
export default Register; | ||
export default Register; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { auth } from "@/auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { UserRole } from "@prisma/client"; | ||
|
||
export async function POST(request: NextRequest, context: { params: { id: string } }) { | ||
const session = await auth(); | ||
if (!session) { | ||
return NextResponse.json( | ||
{ message: "Unauthorized", isOk: false }, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
if (session.user.role !== UserRole.ADMIN) { | ||
return NextResponse.json( | ||
{ message: "Forbidden", isOk: false }, | ||
{ status: 403 } | ||
); | ||
} | ||
|
||
const { id } = context.params; | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: id, | ||
}, | ||
data: { | ||
role: UserRole.ADMIN, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ user }, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { auth } from "@/auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { UserRole } from "@prisma/client"; | ||
|
||
export async function POST(request: NextRequest, context: { params: { id: string } }) { | ||
const session = await auth(); | ||
if (!session) { | ||
return NextResponse.json( | ||
{ message: "Unauthorized", isOk: false }, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
if (session.user.role !== UserRole.ADMIN) { | ||
return NextResponse.json( | ||
{ message: "Forbidden", isOk: false }, | ||
{ status: 403 } | ||
); | ||
} | ||
|
||
const { id } = context.params; | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: id, | ||
}, | ||
data: { | ||
role: UserRole.COORDINATOR, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ user }, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { auth } from "@/auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { UserRole } from "@prisma/client"; | ||
|
||
export async function POST(request: NextRequest, context: { params: { id: string } }) { | ||
const session = await auth(); | ||
if (!session) { | ||
return NextResponse.json( | ||
{ message: "Unauthorized", isOk: false }, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
if (session.user.role !== UserRole.ADMIN) { | ||
return NextResponse.json( | ||
{ message: "Forbidden", isOk: false }, | ||
{ status: 403 } | ||
); | ||
} | ||
|
||
const { id } = context.params; | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: id, | ||
}, | ||
data: { | ||
role: UserRole.PARTICIPANT, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ user }, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { auth } from "@/auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { UserRole } from "@prisma/client"; | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
context: { params: { id: string } } | ||
) { | ||
const session = await auth(); | ||
if (!session) { | ||
return NextResponse.json( | ||
{ message: "Unauthorized", isOk: false }, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
if (session.user.role !== UserRole.ADMIN) { | ||
return NextResponse.json( | ||
{ message: "Forbidden", isOk: false }, | ||
{ status: 403 } | ||
); | ||
} | ||
|
||
const { id } = context.params; | ||
|
||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: id, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ user }, { status: 200 }); | ||
} |
Oops, something went wrong.