commit 9c5d791d10071a0da9e7bcf7932447c96000b6ce Author: LeNei Date: Sat Nov 25 16:18:54 2023 +0100 first commit diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e26540c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +docker +.git +.env.template diff --git a/.env b/.env new file mode 100644 index 0000000..283d87d --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in +NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up +NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard +NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard + diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..8a07ecd --- /dev/null +++ b/.env.template @@ -0,0 +1,2 @@ +NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_pub_key +CLERK_SECRET_KEY=your_clerk_secret_key diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bbb991 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d4f398d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +FROM node:18-alpine AS base + +# 1. Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ + else echo "Lockfile not found." && exit 1; \ + fi + + +# 2. Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +# This will do the trick, use the corresponding env file for each environment. +COPY .env .env.production +RUN npm run build + +# 3. Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +COPY --from=builder /app/public ./public + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" + +CMD ["node", "server.js"] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..452c9ee --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +

+ + + + + + +
+

+
+

+ Clerk and Next.js App Router template +

+ + + + + Discord + + + Twitter + +
+
+ Clerk Hero Image +
+ +## Introduction + +Clerk is a developer-first authentication and user management solution. It provides pre-built React components and hooks for sign-in, sign-up, user profile, and organization management. Clerk is designed to be easy to use and customize, and can be dropped into any React or Next.js application. + +This template allows you to get started with Clerk and Next.js (App Router) in a matter of minutes, and demonstrates features of Clerk such as: + +- Fully functional auth flow with sign-in, sign-up, and a protected page +- Customized Clerk components with Tailwind CSS +- Hooks for accessing user data and authentication state +- Organizations for multi-tenant applications + +## Demo + +A hosted demo of this example is available at https://clerk-nextjs-demo-app-router.clerkpreview.com/ + +## Deploy + +Easily deploy the template to Vercel with the button below. You will need to set the required environment variables in the Vercel dashboard. + + + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fclerkinc%2Fclerk-nextjs-demo-app-router&env=NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,CLERK_SECRET_KEY&envDescription=Clerk%20API%20keys&envLink=https%3A%2F%2Fclerk.com%2Fdocs%2Fquickstart%2Fnextjs&redirect-url=https%3A%2F%2Fclerk.com%2Fdocs%2Fquickstart%2Fnextjs) + +## Running the template + +```bash +git clone https://github.com/clerkinc/clerk-nextjs-demo-app-router +``` + +To run the example locally, you need to: + + + +1. Sign up for a Clerk account at [https://clerk.com](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=template_repos&utm_campaign=nextjs_template). + +2. Go to the [Clerk dashboard](https://dashboard.clerk.com?utm_source=github&utm_medium=template_repos&utm_campaign=nextjs_template) and create an application. +3. Set the required Clerk environment variables as shown in [the example `env` file](./.env.template). +4. `npm install` the required dependencies. +5. `npm run dev` to launch the development server. + +## Learn more + +To learn more about Clerk and Next.js, check out the following resources: + + + +- [Quickstart: Get started with Next.js and Clerk](https://clerk.com/docs/quickstarts/nextjs?utm_source=github&utm_medium=template_repos&utm_campaign=nextjs_template) + +- [Clerk Documentation](https://clerk.com/docs?utm_source=github&utm_medium=template_repos&utm_campaign=nextjs_template) +- [Next.js Documentation](https://nextjs.org/docs) + +## Found an issue? + +If you have found an issue with our documentation, please create an [issue](https://github.com/clerkinc/clerk-nextjs-demo-app-router/issues). + +If it's a quick fix, such as a misspelled word or a broken link, feel free to skip creating an issue. +Go ahead and create a [pull request](https://github.com/clerkinc/clerk-nextjs-demo-app-router/pulls) with the solution. :rocket: + +## Want to leave feedback? + +Feel free to create an [issue](https://github.com/clerkinc/clerk-nextjs-demo-app-router/issues) with the **feedback** label. Our team will take a look at it and get back to you as soon as we can! + +## Connect with us + +You can discuss ideas, ask questions, and meet others from the community in our [Discord](https://discord.com/invite/b5rXHjAg7A). + +If you prefer, you can also find support through our [Twitter](https://twitter.com/ClerkDev), or you can [email](mailto:support@clerk.dev) us! diff --git a/app/assets/components.svg b/app/assets/components.svg new file mode 100644 index 0000000..a0bb267 --- /dev/null +++ b/app/assets/components.svg @@ -0,0 +1,474 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/dashboard/details.tsx b/app/dashboard/details.tsx new file mode 100644 index 0000000..08e8564 --- /dev/null +++ b/app/dashboard/details.tsx @@ -0,0 +1,358 @@ +"use client"; + +import { useOrganization, useSession, useUser } from "@clerk/nextjs"; +import classNames from "classnames"; +import { useEffect, useState } from "react"; +import { CopyIcon, Dot } from "../icons"; +import Image from "next/image"; +import "./prism.css"; + +declare global { + interface Window { + Prism: any; + } +} + +export function UserDetails() { + const { isLoaded, user } = useUser(); + const [jsonOutput, setJsonOutput] = useState(false); + + return ( +
+
+

+ User +

+ + setJsonOutput(!jsonOutput)} + disabled={!isLoaded} + /> +
+ {isLoaded && user ? ( + jsonOutput ? ( +
+ +
+ ) : ( +
+
+
+
User ID
+
+ {user.id} + +
+
+ {user.firstName && ( +
+
First Name
+
+ {user.firstName} +
+
+ )} + {user.lastName && ( +
+
Last Name
+
+ {user.lastName} +
+
+ )} +
+
Email addresses
+
+ {user.emailAddresses.map((email) => ( +
+ {email.emailAddress} + {user.primaryEmailAddressId === email.id && ( + + Primary + + )} +
+ ))} +
+
+ {user.imageUrl && ( +
+
Profile Image
+
+ +
+
+ )} +
+
+ ) + ) : ( +
+ Loading user data... +
+ )} +
+ ); +} + +export function SessionDetails() { + const { isLoaded, session } = useSession(); + const [jsonOutput, setJsonOutput] = useState(false); + + return ( +
+
+

+ Session +

+ setJsonOutput(!jsonOutput)} + disabled={!isLoaded} + /> +
+ {isLoaded && session ? ( + jsonOutput ? ( +
+ +
+ ) : ( +
+
+
+
Session ID
+
+ {session.id} + +
+
+
+
Status
+
+ {session.status === `active` && ( + +
+ +
+ Active +
+ )} +
+
+
+
Last Active
+
+ {session.lastActiveAt.toLocaleString()} +
+
+
+
Expiry
+
+ {session.expireAt.toLocaleString()} +
+
+
+
+ ) + ) : ( +
+ Loading user data... +
+ )} +
+ ); +} + +export function OrgDetails() { + const { isLoaded, organization } = useOrganization(); + const [jsonOutput, setJsonOutput] = useState(false); + + return ( +
+
+

+ Organization +

+ setJsonOutput(!jsonOutput)} + disabled={!(isLoaded && organization)} + /> +
+ {isLoaded ? ( + organization ? ( + jsonOutput ? ( +
+ +
+ ) : ( +
+
+
+
Organization ID
+
+ {organization.id} + +
+
+
+
Name
+
+ {organization.name} +
+
+
+
Members
+
+ {organization.membersCount} +
+
+
+
+ Pending invitations +
+
+ {organization.pendingInvitationsCount} +
+
+
+
Image
+
+ {`Logo +
+
+
+
+ ) + ) : ( +
+ You are currently logged in to your personal workspace. +
+ Create or switch to an organization to see its details. +
+ ) + ) : ( +
+ Loading organization data... +
+ )} +
+ ); +} + +function Toggle(props: { + checked: boolean; + onChange: () => void; + disabled: boolean; +}) { + return ( +
+ + +
+ ); +} + +function CopyButton(props: { text: string }) { + const [tooltipShown, setTooltipShown] = useState(false); + + useEffect(() => { + if (tooltipShown) { + const timeout = setTimeout(() => setTooltipShown(false), 2000); + return () => clearTimeout(timeout); + } + }, [tooltipShown]); + + return ( + <> + + +
+ Copied! +
+ + ); +} + +function JSONOutput(props: { json: any }) { + useEffect(() => { + if (window.Prism) { + console.log(`highlighting`); + window.Prism.highlightAll(); + } + }, []); + + return ( +
+      
+        {JSON.stringify(props.json, null, 2)}
+      
+    
+ ); +} diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..fbbffdb --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,47 @@ +import { auth, clerkClient, useClerk } from "@clerk/nextjs"; +import { redirect, useRouter } from "next/navigation"; +import { OrgDetails, SessionDetails, UserDetails } from "./details"; +import Link from "next/link"; + +export default async function DashboardPage() { + const { userId } = auth(); + const router = useRouter(); + const { signOut } = useClerk(); + + if (!userId) { + redirect("/"); + } + + const user = await clerkClient.users.getUser(userId); + + return ( +
+ {user && ( + <> +

+ 👋 Hi, {user.firstName || `Stranger`} +

+ +
+ + + +
+

+ What's next? +

+ Read the{" "} + + Clerk Docs -> + + + )} +
+ ); +} diff --git a/app/dashboard/prism.css b/app/dashboard/prism.css new file mode 100644 index 0000000..c9d4160 --- /dev/null +++ b/app/dashboard/prism.css @@ -0,0 +1,144 @@ +/** + * prism.js default theme for JavaScript, CSS and HTML + * Based on dabblet (http://dabblet.com) + * @author Lea Verou + */ + +code[class*='language-'], +pre[class*='language-'] { + color: black; + background: none; + text-shadow: 0 1px white; + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-size: 1em; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +pre[class*='language-']::-moz-selection, +pre[class*='language-'] ::-moz-selection, +code[class*='language-']::-moz-selection, +code[class*='language-'] ::-moz-selection { + text-shadow: none; + background: #b3d4fc; +} + +pre[class*='language-']::selection, +pre[class*='language-'] ::selection, +code[class*='language-']::selection, +code[class*='language-'] ::selection { + text-shadow: none; + background: #b3d4fc; +} + +@media print { + code[class*='language-'], + pre[class*='language-'] { + text-shadow: none; + } +} + +/* Code blocks */ +pre[class*='language-'] { + padding: 1em; + margin: 0.5em 0; + overflow: auto; +} + +/* :not(pre) > code[class*='language-'], +pre[class*='language-'] { + background: #f5f2f0; +} */ + +/* Inline code */ +:not(pre) > code[class*='language-'] { + padding: 0.1em; + border-radius: 0.3em; + white-space: normal; +} + +.token.comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: slategray; +} + +.token.punctuation { + color: #999; +} + +.token.namespace { + opacity: 0.7; +} + +.token.property, +.token.tag, +.token.boolean, +.token.number, +.token.constant, +.token.symbol, +.token.deleted { + color: #905; +} + +.token.selector, +.token.attr-name, +.token.string, +.token.char, +.token.builtin, +.token.inserted { + color: #690; +} + +.token.operator, +.token.entity, +.token.url, +.language-css .token.string, +.style .token.string { + color: #9a6e3a; + /* This background color was intended by the author of this theme. */ + background: hsla(0, 0%, 100%, 0.5); +} + +.token.atrule, +.token.attr-value, +.token.keyword { + color: #07a; +} + +.token.function, +.token.class-name { + color: #dd4a68; +} + +.token.regex, +.token.important, +.token.variable { + color: #e90; +} + +.token.important, +.token.bold { + font-weight: bold; +} +.token.italic { + font-style: italic; +} + +.token.entity { + cursor: help; +} diff --git a/app/favicon.ico b/app/favicon.ico new file mode 100644 index 0000000..718d6fe Binary files /dev/null and b/app/favicon.ico differ diff --git a/app/globals.css b/app/globals.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/app/globals.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/app/home.css b/app/home.css new file mode 100644 index 0000000..ea1d5f4 --- /dev/null +++ b/app/home.css @@ -0,0 +1,37 @@ +.gradient { + position: relative; + background-image: repeating-linear-gradient( + to right, + #63DFFA, + #6C47FF, + #63DFFA + ); + z-index: 1; + background-position-x: 0%; + background-size: 200%; + animation: gradimate 3s linear infinite; + background-clip: text; +} + +@keyframes gradimate { + 0% { + background-position-x: 0%; + } + 50% { + background-position-x: 100%; + } + 100% { + background-position-x: 200%; + } +} + +/* .cta .arrow { + opacity: 0; + transition: 0.1s linear; + margin-left: -4px; +} + +.cta:hover .arrow { + opacity: 100; + margin-left: 0; +} */ \ No newline at end of file diff --git a/app/icons/index.tsx b/app/icons/index.tsx new file mode 100644 index 0000000..7691e5b --- /dev/null +++ b/app/icons/index.tsx @@ -0,0 +1,181 @@ +export function RightArrow() { + return ( + + + + ); +} + +export function DownArrow() { + return ( + + + + ); +} + +export function CopyIcon() { + return ( + + + + ); +} + +export function Times() { + return ( + + + + ); +} + +export function Dot() { + return ( + + + + ); +} + +export function Docs() { + return ( + + + + ); +} + +export function Github() { + return ( + + + + ); +} + +export function Twitter() { + return ( + + + + ); +} + +export function Discord() { + return ( + + + + + + + + + + + ); +} diff --git a/app/layout.tsx b/app/layout.tsx new file mode 100644 index 0000000..ff2fff3 --- /dev/null +++ b/app/layout.tsx @@ -0,0 +1,140 @@ +import { + ClerkProvider, + OrganizationSwitcher, + SignedIn, + UserButton, +} from "@clerk/nextjs"; +import "./globals.css"; +import { Inter } from "next/font/google"; +import Image from "next/image"; +import Link from "next/link"; +import Script from "next/script"; +import { Docs, Github, Times } from "./icons"; +import { Twitter } from "./icons"; +import { Discord } from "./icons"; +import { Metadata } from "next"; + +const inter = Inter({ subsets: ["latin"] }); + +export const metadata: Metadata = { + title: "Next.js Clerk Template", + description: + "A simple and powerful Next.js template featuring authentication and user management powered by Clerk.", + openGraph: { images: ["/og.png"] }, +}; + +export default function RootLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + + + +
+ + Clerk Logo + + Next.js Logo + +
+ +
+ +
+
+ +
+ +
+
+
{children}
+ + +
+ +