Skip to content

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

Merge branch 'feat/passkey' into email-magic-link

Marc Seitze98f005a073c
diff --cc app/(auth)/login/page.tsx
index 8ad9949f,1dda7d5a..2c78feba
--- a/app/(auth)/login/page.tsx
+++ b/app/(auth)/login/page.tsx
@@@ -1,12 -1,14 +1,16 @@@
+ "use client";
+
import { Button } from "@/components/ui/button";
import { signIn } from "next-auth/react";
+ import { signInWithPasskey } from "@teamhanko/passkeys-next-auth-provider/client";
import Link from "next/link";
+import { useRouter } from "next/router";
+import { Input } from "@/components/ui/input";
+ import { useParams } from "next/navigation";
+ import Passkey from "@/components/shared/icons/passkey";
export default function Login() {
- const router = useRouter();
- const { next } = router.query as { next?: string };
+ const { next } = useParams as { next?: string };
return (
<div className="flex h-screen w-screen justify-center">
@@@ -33,21 -35,7 +37,21 @@@
Start sharing documents
</h3>
</div>
+ <form
+ className="flex flex-col p-4 pt-8 sm:px-16 gap-4"
+ onSubmit={(e) => {
+ e.preventDefault();
+ const form = e.target as HTMLFormElement;
+ signIn("email", {
+ email: (form.elements[0] as HTMLInputElement).value,
+ });
+ }}
+ >
+ <Input className=" border-4" placeholder="[email protected]" />
+ <Button type="submit">Continue with Email</Button>
+ </form>
+ <p className="text-center">or</p>
- <div className="flex flex-col p-4 sm:px-16">
+ <div className="flex flex-col px-4 py-8 sm:px-16 space-y-2">
<Button
onClick={() => {
signIn("google", {
@@@ -64,7 -52,19 +68,19 @@@
>
<path d="M488 261.8C488 403.3 391.1 504 248 504 110.8 504 0 393.2 0 256S110.8 8 248 8c66.8 0 123 24.5 166.3 64.9l-67.5 64.9C258.5 52.6 94.3 116.6 94.3 256c0 86.5 69.1 156.6 153.7 156.6 98.2 0 135-70.4 140.8-106.9H248v-85.3h236.1c2.3 12.7 3.9 24.9 3.9 41.4z" />
</svg>
-- <span>Continue with Google</span>
++ <span>Sign in with Google</span>
+ </Button>
+ <Button
+ onClick={() =>
+ signInWithPasskey({
+ tenantId: process.env.NEXT_PUBLIC_HANKO_TENANT_ID as string,
+ })
+ }
+ variant="outline"
+ className="flex justify-center items-center space-x-2"
+ >
+ <Passkey className="w-4 h-4" />
+ <span>Sign in with a passkey</span>
</Button>
</div>
</div>
diff --cc pages/api/auth/[...nextauth].ts
index f3c081a6,76914e3c..19c2390c
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].ts
@@@ -5,8 -5,8 +5,10 @@@ import prisma from "@/lib/prisma"
import { CreateUserEmailProps, CustomUser } from "@/lib/types";
import { sendWelcomeEmail } from "@/lib/emails/send-welcome";
import { analytics, identifyUser, trackAnalytics } from "@/lib/analytics";
+import EmailProvider from "next-auth/providers/email";
+import { sendVerificationRequestEmail } from "@/lib/emails/send-verification-request";
+ import { PasskeyProvider } from "@teamhanko/passkeys-next-auth-provider";
+ import hanko from "@/lib/hanko";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
@@@ -21,19 -21,14 +23,27 @@@ export const authOptions: NextAuthOptio
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}),
+ EmailProvider({
+ sendVerificationRequest({ identifier, url }) {
+ if (process.env.NODE_ENV === "development") {
+ console.log(`Login link: ${url}`);
+ return;
+ } else {
+ sendVerificationRequestEmail({
+ url,
+ email: identifier,
+ });
+ }
+ },
+ }),
+ PasskeyProvider({
+ tenant: hanko,
+ async authorize({ userId }) {
+ const user = await prisma.user.findUnique({ where: { id: userId } });
+ if (!user) return null;
+ return user;
+ },
+ }),
],
adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" },