Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

add authentication

Marc Seitzb720cf05f531
diff --git a/lib/prisma.ts b/lib/prisma.ts
new file mode 100644
index 00000000..10082dc2
--- /dev/null
+++ b/lib/prisma.ts
@@ -0,0 +1,11 @@
+import { PrismaClient } from "@prisma/client";
+
+declare global {
+ var prisma: PrismaClient | undefined;
+}
+
+const prisma = global.prisma || new PrismaClient();
+
+if (process.env.NODE_ENV === "development") global.prisma = prisma;
+
+export default prisma;
diff --git a/lib/types.ts b/lib/types.ts
new file mode 100644
index 00000000..6599f495
--- /dev/null
+++ b/lib/types.ts
@@ -0,0 +1,5 @@
+import { User as NextAuthUser } from "next-auth";
+
+export interface CustomUser extends NextAuthUser {
+ id: string;
+}
diff --git a/package.json b/package.json
index 4017da59..78638c28 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,8 @@
"lint": "next lint"
},
"dependencies": {
+ "@next-auth/prisma-adapter": "^1.0.6",
+ "@prisma/client": "^4.14.1",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
@@ -16,10 +18,14 @@
"eslint": "8.41.0",
"eslint-config-next": "13.4.4",
"next": "13.4.4",
+ "next-auth": "^4.22.1",
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"typescript": "5.0.4"
+ },
+ "devDependencies": {
+ "prisma": "^4.14.1"
}
}
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 021681f4..6d7a178a 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -1,6 +1,20 @@
-import '@/styles/globals.css'
-import type { AppProps } from 'next/app'
+import "@/styles/globals.css";
+import type { AppProps } from "next/app";
+import { Inter } from "next/font/google";
+import type { Session } from "next-auth";
+import { SessionProvider } from "next-auth/react";
-export default function App({ Component, pageProps }: AppProps) {
- return <Component {...pageProps} />
+const inter = Inter({ subsets: ["latin"] });
+
+export default function App({
+ Component,
+ pageProps: { session, ...pageProps },
+}: AppProps<{ session: Session }>) {
+ return (
+ <SessionProvider session={session}>
+ <main className={inter.className}>
+ <Component {...pageProps} />
+ </main>
+ </SessionProvider>
+ );
}
diff --git a/pages/_document.tsx b/pages/_document.tsx
index 54e8bf3e..13c79e0b 100644
--- a/pages/_document.tsx
+++ b/pages/_document.tsx
@@ -1,13 +1,13 @@
-import { Html, Head, Main, NextScript } from 'next/document'
+import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
- <Html lang="en">
+ <Html lang="en" className="h-full bg-black">
<Head />
- <body>
+ <body className="h-full">
<Main />
<NextScript />
</body>
</Html>
- )
+ );
}
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts
new file mode 100644
index 00000000..772b6978
--- /dev/null
+++ b/pages/api/auth/[...nextauth].ts
@@ -0,0 +1,43 @@
+import NextAuth, { type NextAuthOptions } from "next-auth";
+import GoogleProvider from "next-auth/providers/google";
+import { PrismaAdapter } from "@next-auth/prisma-adapter";
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+
+const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
+
+export const authOptions: NextAuthOptions = {
+ providers: [
+ GoogleProvider({
+ clientId: process.env.GOOGLE_CLIENT_ID as string,
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
+ }),
+ ],
+ adapter: PrismaAdapter(prisma),
+ session: { strategy: "jwt" },
+ cookies: {
+ sessionToken: {
+ name: `${VERCEL_DEPLOYMENT ? "__Secure-" : ""}next-auth.session-token`,
+ options: {
+ httpOnly: true,
+ sameSite: "lax",
+ path: "/",
+ // When working on localhost, the cookie domain must be omitted entirely (https://stackoverflow.com/a/1188145)
+ domain: VERCEL_DEPLOYMENT ? "everything.to" : undefined,
+ secure: VERCEL_DEPLOYMENT,
+ },
+ },
+ },
+ callbacks: {
+ session: async ({ session, token }) => {
+ (session.user as CustomUser) = {
+ // @ts-ignore
+ id: token.sub,
+ ...session.user,
+ };
+ return session;
+ },
+ },
+};
+
+export default NextAuth(authOptions);
diff --git a/pages/api/hello.ts b/pages/api/hello.ts
deleted file mode 100644
index f8bcc7e5..00000000
--- a/pages/api/hello.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
-import type { NextApiRequest, NextApiResponse } from 'next'
-
-type Data = {
- name: string
-}
-
-export default function handler(
- req: NextApiRequest,
- res: NextApiResponse<Data>
-) {
- res.status(200).json({ name: 'John Doe' })
-}
diff --git a/pages/index.tsx b/pages/index.tsx
index 14f2678f..f9bba79b 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,118 +1,69 @@
-import Image from 'next/image'
-import { Inter } from 'next/font/google'
+import { signIn, useSession } from "next-auth/react";
+import Link from "next/link";
-const inter = Inter({ subsets: ['latin'] })
+export default function Example() {
+ const { data: session } = useSession();
-export default function Home() {
+ function signInOrRedirect() {
+ if (session) {
+ window.location.href = "/documents/new";
+ } else {
+ signIn("google", {
+ callbackUrl: `${window.location.origin}/documents/new`,
+ });
+ }
+ }
return (
- <main
- className={`flex min-h-screen flex-col items-center justify-between p-24 ${inter.className}`}
- >
- <div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
- <p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
- Get started by editing&nbsp;
- <code className="font-mono font-bold">pages/index.tsx</code>
- </p>
- <div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
- <a
- className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
- href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
- target="_blank"
- rel="noopener noreferrer"
- >
- By{' '}
- <Image
- src="/vercel.svg"
- alt="Vercel Logo"
- className="dark:invert"
- width={100}
- height={24}
- priority
- />
- </a>
- </div>
- </div>
-
- <div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700/10 after:dark:from-sky-900 after:dark:via-[#0141ff]/40 before:lg:h-[360px]">
- <Image
- className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
- src="/next.svg"
- alt="Next.js Logo"
- width={180}
- height={37}
- priority
+ <div className="max-h-screen relative isolate overflow-hidden bg-black">
+ <div
+ className="absolute left-[calc(50%-4rem)] top-10 -z-10 transform-gpu blur-3xl sm:left-[calc(50%-18rem)] lg:left-48 lg:top-[calc(50%-30rem)] xl:left-[calc(50%-24rem)]"
+ aria-hidden="true"
+ >
+ <div
+ className="aspect-[1108/632] w-[69.25rem] bg-gradient-to-r from-[#80caff] to-[#4f46e5] opacity-20"
+ style={{
+ clipPath:
+ "polygon(73.6% 51.7%, 91.7% 11.8%, 100% 46.4%, 97.4% 82.2%, 92.5% 84.9%, 75.7% 64%, 55.3% 47.5%, 46.5% 49.4%, 45% 62.9%, 50.3% 87.2%, 21.3% 64.1%, 0.1% 100%, 5.4% 51.1%, 21.4% 63.9%, 58.9% 0.2%, 73.6% 51.7%)",
+ }}
/>
</div>
-
- <div className="mb-32 grid text-center lg:mb-0 lg:grid-cols-4 lg:text-left">
- <a
- href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
- className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
- target="_blank"
- rel="noopener noreferrer"
- >
- <h2 className={`mb-3 text-2xl font-semibold`}>
- Docs{' '}
- <span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
- -&gt;
- </span>
- </h2>
- <p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
- Find in-depth information about Next.js features and API.
- </p>
- </a>
-
- <a
- href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
- className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
- target="_blank"
- rel="noopener noreferrer"
- >
- <h2 className={`mb-3 text-2xl font-semibold`}>
- Learn{' '}
- <span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
- -&gt;
- </span>
- </h2>
- <p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
- Learn about Next.js in an interactive course with&nbsp;quizzes!
+ <div className="mx-auto max-w-7xl px-6 pb-24 pt-10 sm:pb-32 lg:flex lg:px-8 lg:py-40">
+ <div className="mx-auto max-w-2xl flex-shrink-0 lg:mx-0 lg:max-w-xl lg:pt-8">
+ <h1 className="mt-10 text-4xl font-bold text-white sm:text-6xl tracking-tighter">
+ Papermark
+ </h1>
+ <p className="mt-6 text-lg leading-8 text-gray-300">
+ The dynamic open-source alternative to DocSend. We're on a mission
+ to revolutionize content sharing and collaboration.
</p>
- </a>
-
- <a
- href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
- className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
- target="_blank"
- rel="noopener noreferrer"
- >
- <h2 className={`mb-3 text-2xl font-semibold`}>
- Templates{' '}
- <span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
- -&gt;
- </span>
- </h2>
- <p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
- Discover and deploy boilerplate example Next.js&nbsp;projects.
- </p>
- </a>
-
- <a
- href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
- className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
- target="_blank"
- rel="noopener noreferrer"
- >
- <h2 className={`mb-3 text-2xl font-semibold`}>
- Deploy{' '}
- <span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
- -&gt;
- </span>
- </h2>
- <p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
- Instantly deploy your Next.js site to a shareable URL with Vercel.
- </p>
- </a>
+ <div className="mt-10 flex items-center gap-x-6">
+ <Link
+ onClick={() => signInOrRedirect()}
+ className="rounded-md bg-indigo-500 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-400"
+ href={""}
+ >
+ Get started
+ </Link>
+ <Link
+ href="https://github.com/mfts"
+ className="text-sm font-semibold leading-6 text-white"
+ >
+ View on GitHub
+ </Link>
+ </div>
+ </div>
+ <div className="mx-auto mt-16 flex max-w-2xl sm:mt-24 lg:ml-10 lg:mr-0 lg:mt-0 lg:max-w-none lg:flex-none xl:ml-32">
+ <div className="max-w-3xl flex-none sm:max-w-5xl lg:max-w-none">
+ <img
+ src={`${process.env.NEXT_PUBLIC_BASE_URL}/papermark.png`}
+ alt="App screenshot"
+ width={2432}
+ height={1442}
+ className="w-[76rem] rounded-md bg-white/5 shadow-2xl ring-1 ring-white/10"
+ />
+ </div>
+ </div>
</div>
- </main>
- )
+ </div>
+ );
}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 00000000..9cfda328
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,55 @@
+datasource db {
+ provider = "postgresql"
+ url = env("POSTGRES_PRISMA_URL") // uses connection pooling
+ directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
+ shadowDatabaseUrl = env("POSTGRES_URL_NON_POOLING") // used for migrations
+ }
+
+generator client {
+ provider = "prisma-client-js"
+}
+
+model Account {
+ id String @id @default(cuid())
+ userId String
+ type String
+ provider String
+ providerAccountId String
+ refresh_token String? @db.Text
+ access_token String? @db.Text
+ expires_at Int?
+ token_type String?
+ scope String?
+ id_token String? @db.Text
+ session_state String?
+
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+
+ @@unique([provider, providerAccountId])
+}
+
+model Session {
+ id String @id @default(cuid())
+ sessionToken String @unique
+ userId String
+ expires DateTime
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+}
+
+model User {
+ id String @id @default(cuid())
+ name String?
+ email String? @unique
+ emailVerified DateTime?
+ image String?
+ accounts Account[]
+ sessions Session[]
+}
+
+model VerificationToken {
+ identifier String
+ token String @unique
+ expires DateTime
+
+ @@unique([identifier, token])
+}
diff --git a/public/papermark.png b/public/papermark.png
new file mode 100644
index 00000000..47c78eb1
Binary files /dev/null and b/public/papermark.png differ