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 }); + }} + > + + + + Email address + + + + + + + + + Sign up + + + + + ); +} 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 - + - - {session?.user.name} + {session?.user.image ? ( + + ) : null} + {session?.user.name} diff --git a/src/server/auth.ts b/src/server/auth.ts index 81613bc6..74ec1a92 100644 --- a/src/server/auth.ts +++ b/src/server/auth.ts @@ -45,16 +45,42 @@ export const authOptions: NextAuthOptions = { }), }, adapter: DrizzleAdapter(db, mysqlTable), + pages: { + signIn: "/auth/login", + // signOut: "/auth/signout", + // error: "/auth/error", + verifyRequest: "/auth/verify", + }, providers: [ - /** - * ...add more providers here. - * - * Most other providers require a bit more work than the Discord provider. For example, the - * GitHub provider requires you to add the `refresh_token_expires_in` field to the Account - * model. Refer to the NextAuth.js docs for the provider you want to use. Example: - * - * @see https://next-auth.js.org/providers/github - */ + { + id: 'email', + type: 'email', + from: process.env.EMAIL_FROM ?? '', + server: {}, + maxAge: 24 * 60 * 60, + name: 'Email', + options: {}, + async sendVerificationRequest({ identifier: email, url }) { + await fetch(process.env.EMAIL_URL ?? '', { + method: "POST", + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.EMAIL_TOKEN}`, + }, + body: JSON.stringify({ + from: process.env.EMAIL_FROM, + to: [email], + subject: 'Login via email', + html: `${url}`, + }), + }) + + // if (!response.ok) { + // const { errors } = await response.json() + // throw new Error(JSON.stringify(errors)) + // } + }, + } ], };
Get started
+ {"Already have an account?"} +
Check your inbox
+ {`Click on the link we've sent to you@example.com to sign in.`} +
{session?.user.name}