Skip to content

Commit

Permalink
Merge pull request #1 from bercivarga/feature/auth
Browse files Browse the repository at this point in the history
Add auth with Clerk
  • Loading branch information
bercivarga authored Mar 8, 2024
2 parents 68a5a04 + 2a2632f commit fd7c7b6
Show file tree
Hide file tree
Showing 13 changed files with 674 additions and 43 deletions.
20 changes: 20 additions & 0 deletions app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Link from "next/link";

export default function AuthLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<div>
<nav className="absolute left-0 top-0 w-full p-6 text-center text-white">
<Link href="/">
<span className="text-2xl font-bold">Home</span>
</Link>
</nav>
<main className="flex min-h-screen items-center justify-center bg-slate-900">
{children}
</main>
</div>
);
}
5 changes: 5 additions & 0 deletions app/(auth)/sign-in/[[...sign-in]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SignIn } from "@clerk/nextjs";

export default function SignInPage() {
return <SignIn redirectUrl={"/dashboard"} />;
}
5 changes: 5 additions & 0 deletions app/(auth)/sign-up/[[...sign-up]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SignUp } from "@clerk/nextjs";

export default function SignUpPage() {
return <SignUp />;
}
7 changes: 7 additions & 0 deletions app/(marketing)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function MarketingLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <>{children}</>;
}
42 changes: 42 additions & 0 deletions app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { auth } from "@clerk/nextjs";
import { Metadata } from "next";
import Link from "next/link";

import { Button } from "@/components/ui/button";

export const metadata: Metadata = {
title: "CF Showcase Project",
description: "Made for CLEVER°FRANKE by @berci.dev",
};

export default function Home() {
const { userId } = auth();

return (
<main className="flex min-h-screen items-center justify-center">
<div className="flex flex-col gap-4 p-6 md:items-center md:text-center">
<h2>
Welcome to the
<br /> CF Showcase
</h2>
<p>Sign in or sign up in order to explore the app.</p>
<div className="flex gap-2">
{userId ? (
<Link href="/dashboard">
<Button>To dashboard</Button>
</Link>
) : (
<>
<Link href="/sign-in">
<Button>Sign in</Button>
</Link>
<Link href="/sign-up">
<Button variant="outline">Sign up</Button>
</Link>
</>
)}
</div>
</div>
</main>
);
}
21 changes: 21 additions & 0 deletions app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { UserButton } from "@clerk/nextjs";

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<div className="flex h-screen">
<aside className="flex h-full w-64 flex-col justify-between bg-indigo-100 p-6">
<div>
<span>TODO: Add sidebar menu</span>
</div>
<div>
<UserButton afterSignOutUrl="/" />
</div>
</aside>
{children}
</div>
);
}
15 changes: 15 additions & 0 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Metadata } from "next";

export const metadata: Metadata = {
title: "Dashboard",
description: "Start working on your ideas here.",
};

export default function Home() {
return (
<main>
<h1>Dashboard</h1>
<p>hi</p>
</main>
);
}
25 changes: 14 additions & 11 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "@/styles/globals.css";

import { ClerkProvider } from "@clerk/nextjs";
import { Archivo_Black, Inter } from "next/font/google";
import { twMerge } from "tailwind-merge";

Expand All @@ -22,16 +23,18 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={twMerge(
bodyFont.variable,
displayFont.variable,
"antialiased"
)}
>
{children}
</body>
</html>
<ClerkProvider>
<html lang="en">
<body
className={twMerge(
bodyFont.variable,
displayFont.variable,
"antialiased"
)}
>
{children}
</body>
</html>
</ClerkProvider>
);
}
23 changes: 0 additions & 23 deletions app/page.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({
// Routes that can be accessed while signed out
publicRoutes: [
/^(?!\/dashboard).*/, // Match routes that don't start with "/dashboard"
],
// Routes that can always be accessed, and have
// no authentication information
// ignoredRoutes: ["/no-auth-in-this-route"],
});

export const config = {
// Protects all routes, including api/trpc.
// See https://clerk.com/docs/references/nextjs/auth-middleware
// for more information about configuring your Middleware
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
Loading

0 comments on commit fd7c7b6

Please sign in to comment.