From 6fb43dc25cc54c8751c9c1f357ecc71c4978e38c Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 30 Oct 2023 17:56:54 +0000 Subject: [PATCH] feat: setup magic link login via next auth --- next.config.mjs | 13 ++++++++- package.json | 1 + src/app/_components/auth.tsx | 52 ++++++++++++++++++++++++++++++++++++ src/app/auth/login/page.tsx | 20 ++++++++++++++ src/app/auth/verify/page.tsx | 12 +++++++++ src/app/boards/layout.tsx | 28 ++++++++++--------- src/server/auth.ts | 44 +++++++++++++++++++++++------- 7 files changed, 147 insertions(+), 23 deletions(-) create mode 100644 src/app/_components/auth.tsx create mode 100644 src/app/auth/login/page.tsx create mode 100644 src/app/auth/verify/page.tsx diff --git a/next.config.mjs b/next.config.mjs index 0914d313..65764c2d 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -5,6 +5,17 @@ await import("./src/env.mjs"); /** @type {import("next").NextConfig} */ -const config = {}; +const config = { + images: { + remotePatterns: [ + { + protocol: "https", + hostname: "storage.googleapis.com", + port: "", + pathname: "/**", + }, + ], + }, +}; export default config; diff --git a/package.json b/package.json index 7cbf640d..81ec94d2 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@trpc/react-query": "^10.37.1", "@trpc/server": "^10.37.1", "drizzle-orm": "^0.28.5", + "formik": "^2.4.5", "next": "^13.5.4", "next-auth": "^4.24.4", "react": "18.2.0", diff --git a/src/app/_components/auth.tsx b/src/app/_components/auth.tsx new file mode 100644 index 00000000..bfd91273 --- /dev/null +++ b/src/app/_components/auth.tsx @@ -0,0 +1,52 @@ +"use client"; + +import { Formik, Form, Field } from "formik"; +import { signIn } from "next-auth/react"; + +interface FormValues { + email: string; +} + +export function Login() { + return ( + { + await signIn("email", { email: values.email }); + }} + > +
+
+ +
+ +
+
+ +
+ +
+
+
+ ); +} diff --git a/src/app/auth/login/page.tsx b/src/app/auth/login/page.tsx new file mode 100644 index 00000000..332c5e17 --- /dev/null +++ b/src/app/auth/login/page.tsx @@ -0,0 +1,20 @@ +import { Login } from "~/app/_components/auth"; + +export default function LoginPage() { + return ( +
+

+ 貫 kan +

+

Get started

+
+
+ +
+
+

+ {"Already have an account?"} +

+
+ ); +} diff --git a/src/app/auth/verify/page.tsx b/src/app/auth/verify/page.tsx new file mode 100644 index 00000000..33e9a9c2 --- /dev/null +++ b/src/app/auth/verify/page.tsx @@ -0,0 +1,12 @@ +export default function VerifyPage() { + return ( +
+

Check your inbox

+
+

+ {`Click on the link we've sent to you@example.com to sign in.`} +

+
+
+ ); +} diff --git a/src/app/boards/layout.tsx b/src/app/boards/layout.tsx index 75bc7679..de16e8c2 100644 --- a/src/app/boards/layout.tsx +++ b/src/app/boards/layout.tsx @@ -21,7 +21,7 @@ const NavButton: React.FC<{ href={href} className={classNames( current ? "bg-dark-400 text-white" : "bg-dark-400 text-white", - "text-dark-1000 group flex items-center gap-x-3 rounded-md p-1.5 text-sm font-normal leading-6", + "group flex items-center gap-x-3 rounded-md p-1.5 text-sm font-normal leading-6 text-dark-1000", )} > {name} @@ -34,26 +34,28 @@ export default async function Layout(props: { children: React.ReactNode }) { if (!session?.user) redirect("api/auth/signin"); return ( -
-
+
+
-

+

貫 kan

-