Skip to content

Commit

Permalink
feat: 認証実装
Browse files Browse the repository at this point in the history
  • Loading branch information
namidapoo committed Dec 26, 2024
1 parent 16ee3ff commit 6c93dd2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { handlers } from "@/lib/auth";

export const runtime = "edge";
export const { GET, POST } = handlers;
Binary file modified bun.lockb
Binary file not shown.
5 changes: 5 additions & 0 deletions lib/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [GitHub],
});
14 changes: 14 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { auth } from "@/lib/auth";
import { type NextRequest, NextResponse } from "next/server";

export async function middleware(req: NextRequest) {
const session = await auth();
if (!session) {
return NextResponse.redirect(new URL("/api/auth/signin", req.url));
}
return NextResponse.next();
}

export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"clsx": "^2.1.1",
"lucide-react": "^0.469.0",
"next": "15.1.2",
"next-auth": "^5.0.0-beta.25",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwind-merge": "^2.5.5",
Expand Down

0 comments on commit 6c93dd2

Please sign in to comment.