Skip to content

Commit cfb0bf3

Browse files
add auth
1 parent cd19c02 commit cfb0bf3

File tree

10 files changed

+363
-39
lines changed

10 files changed

+363
-39
lines changed

app/(auth)/layout.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
3+
const Layout = ({ children }: { children: React.ReactNode }) => {
4+
return (
5+
<main className="flex min-h-screen w-full items-center justify-center">
6+
{children}
7+
</main>
8+
);
9+
};
10+
11+
export default Layout;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { SignIn } from "@clerk/nextjs";
2+
3+
export default function Page() {
4+
return <SignIn />;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { SignUp } from "@clerk/nextjs";
2+
3+
export default function Page() {
4+
return <SignUp />;
5+
}

app/(root)/(home)/page.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use client";
2+
3+
import { UserButton } from "@clerk/nextjs";
4+
5+
const DotIcon = () => {
6+
return (
7+
<svg
8+
xmlns="http://www.w3.org/2000/svg"
9+
viewBox="0 0 512 512"
10+
fill="currentColor"
11+
>
12+
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
13+
</svg>
14+
);
15+
};
16+
17+
export default function Home() {
18+
return (
19+
<header>
20+
<UserButton>
21+
<UserButton.MenuItems>
22+
<UserButton.Action
23+
label="Open chat"
24+
labelIcon={<DotIcon />}
25+
onClick={() => alert("init chat")}
26+
/>
27+
</UserButton.MenuItems>
28+
</UserButton>
29+
</header>
30+
);
31+
}

app/(root)/ask-question/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from "react";
2+
3+
const page = () => {
4+
return <div>Ask Question</div>;
5+
};
6+
7+
export default page;

app/layout.tsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
1-
import type { Metadata } from "next";
2-
import localFont from "next/font/local";
1+
import {
2+
ClerkProvider,
3+
SignInButton,
4+
SignedIn,
5+
SignedOut,
6+
UserButton,
7+
} from "@clerk/nextjs";
38
import "./globals.css";
4-
5-
const geistSans = localFont({
6-
src: "./fonts/GeistVF.woff",
7-
variable: "--font-geist-sans",
8-
weight: "100 900",
9-
});
10-
const geistMono = localFont({
11-
src: "./fonts/GeistMonoVF.woff",
12-
variable: "--font-geist-mono",
13-
weight: "100 900",
14-
});
15-
16-
export const metadata: Metadata = {
17-
title: "Create Next App",
18-
description: "Generated by create next app",
19-
};
20-
219
export default function RootLayout({
2210
children,
23-
}: Readonly<{
11+
}: {
2412
children: React.ReactNode;
25-
}>) {
13+
}) {
2614
return (
27-
<html lang="en">
28-
<body
29-
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
30-
>
31-
{children}
32-
</body>
33-
</html>
15+
<ClerkProvider>
16+
<html lang="en">
17+
<body>{children}</body>
18+
</html>
19+
</ClerkProvider>
3420
);
3521
}

app/page.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

middleware.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
2+
3+
const isPublicRoute = createRouteMatcher(["/sign-in(.*)", "/sign-up(.*)"]);
4+
5+
export default clerkMiddleware((auth, request) => {
6+
if (!isPublicRoute(request)) {
7+
auth().protect();
8+
}
9+
});
10+
11+
export const config = {
12+
matcher: [
13+
// Skip Next.js internals and all static files, unless found in search params
14+
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
15+
// Always run for API routes
16+
"/(api|trpc)(.*)",
17+
],
18+
};

0 commit comments

Comments
 (0)