Skip to content

Commit

Permalink
feat: add auth
Browse files Browse the repository at this point in the history
  • Loading branch information
drewradcliff committed Jul 22, 2024
1 parent c71b16a commit ca8f05e
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Clerk
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=

# Upstash
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
20 changes: 17 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import type { Metadata } from "next";
import { GeistSans } from "geist/font/sans";
import "@/globals.css";
import { ClerkProvider, SignedIn, SignOutButton } from "@clerk/nextjs";

export const metadata: Metadata = {
title: "mmmines",
};

export default function RootLayout(props: Readonly<React.PropsWithChildren>) {
return (
<html lang="en">
<body className={GeistSans.className}>{props.children}</body>
</html>
<ClerkProvider>
<html lang="en">
<body className={GeistSans.className}>
<div className="p-10">
<h1 className="text-4xl">mmmines</h1>
<SignedIn>
<SignOutButton />
</SignedIn>
<div className="pb-10" />
<div className="flex flex-col items-center justify-center">
{props.children}
</div>
</div>
</body>
</html>
</ClerkProvider>
);
}
6 changes: 1 addition & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Field } from "@/components/field";

export default function App() {
return (
<div className="flex h-screen items-center justify-center">
<Field />
</div>
);
return <Field />;
}
11 changes: 11 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";

const isProtectedRoute = createRouteMatcher(["/(.*)"]);

export default clerkMiddleware((auth, req) => {
if (isProtectedRoute(req)) auth().protect();
});

export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api)(.*)"],
};
235 changes: 235 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"prepare": "husky"
},
"dependencies": {
"@clerk/nextjs": "^5.2.4",
"@upstash/redis": "^1.32.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
Expand Down

0 comments on commit ca8f05e

Please sign in to comment.