Skip to content

Commit f1bd725

Browse files
committed
securing endpoints
1 parent e269729 commit f1bd725

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1+
import { authOptions } from "@/app/auth/authOptions";
12
import NextAuth from "next-auth";
2-
import GoogleProvider from "next-auth/providers/google";
3-
import { PrismaAdapter } from "@auth/prisma-adapter";
4-
import prisma from "@/prisma/client";
53

6-
const handler = NextAuth({
7-
adapter: PrismaAdapter(prisma),
8-
providers: [
9-
GoogleProvider({
10-
clientId: process.env.GOOGLE_CLIENT_ID!,
11-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
12-
}),
13-
],
14-
});
4+
const handler = NextAuth(authOptions);
155

166
export { handler as GET, handler as POST };

app/auth/authOptions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import GoogleProvider from "next-auth/providers/google";
2+
import { PrismaAdapter } from "@auth/prisma-adapter";
3+
import prisma from "@/prisma/client";
4+
5+
export const authOptions = {
6+
adapter: PrismaAdapter(prisma),
7+
providers: [
8+
GoogleProvider({
9+
clientId: process.env.GOOGLE_CLIENT_ID!,
10+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
11+
}),
12+
],
13+
};

app/issues/[id]/page.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { notFound } from "next/navigation";
44
import EditIssueButton from "./EditIssueButton";
55
import IssueDetails from "./IssueDetails";
66
import DeleteIssueButton from "./DeleteIssueButton";
7+
import { getServerSession } from "next-auth";
8+
import { authOptions } from "@/app/auth/authOptions";
79

810
interface Props {
911
params: Promise<{
@@ -12,6 +14,7 @@ interface Props {
1214
}
1315

1416
const IssueDetailPage = async ({ params }: Props) => {
17+
const session = await getServerSession(authOptions);
1518
const { id } = await params;
1619

1720
const issue = await prisma.issue.findUnique({
@@ -26,12 +29,14 @@ const IssueDetailPage = async ({ params }: Props) => {
2629
<Box className="md:col-span-4">
2730
<IssueDetails issue={issue} />
2831
</Box>
29-
<Box>
30-
<Flex direction="column" gap="4">
31-
<EditIssueButton issueId={issue.id} />
32-
<DeleteIssueButton issueId={issue.id} />
33-
</Flex>
34-
</Box>
32+
{session && (
33+
<Box>
34+
<Flex direction="column" gap="4">
35+
<EditIssueButton issueId={issue.id} />
36+
<DeleteIssueButton issueId={issue.id} />
37+
</Flex>
38+
</Box>
39+
)}
3540
</Grid>
3641
);
3742
};

middleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default } from "next-auth/middleware";
2+
3+
export const config = {
4+
matcher: [],
5+
};

0 commit comments

Comments
 (0)