diff --git a/src/app/components/auth.tsx b/src/app/components/auth.tsx index 9c94a39f..2ff66ee4 100644 --- a/src/app/components/auth.tsx +++ b/src/app/components/auth.tsx @@ -1,22 +1,23 @@ "use client"; import { Formik, Form, Field } from "formik"; -import { signIn } from "next-auth/react"; +import { api } from "~/trpc/react"; interface FormValues { email: string; } export function Login() { + const login = api.auth.login.useMutation(); + return ( { - await signIn("email", { + onSubmit={(values: FormValues) => { + login.mutate({ email: values.email, - callbackUrl: "/boards", }); }} > diff --git a/src/server/api/root.ts b/src/server/api/root.ts index 160b7ca5..909a7a46 100644 --- a/src/server/api/root.ts +++ b/src/server/api/root.ts @@ -1,3 +1,4 @@ +import { authRouter } from "~/server/api/routers/auth"; import { boardRouter } from "~/server/api/routers/board"; import { cardRouter } from "~/server/api/routers/card"; import { labelRouter } from "~/server/api/routers/label"; @@ -12,6 +13,7 @@ import { createTRPCRouter } from "~/server/api/trpc"; * All routers added in /api/routers should be manually added here. */ export const appRouter = createTRPCRouter({ + auth: authRouter, board: boardRouter, card: cardRouter, label: labelRouter, diff --git a/src/server/api/routers/auth.ts b/src/server/api/routers/auth.ts new file mode 100644 index 00000000..1eee2233 --- /dev/null +++ b/src/server/api/routers/auth.ts @@ -0,0 +1,25 @@ +import { z } from "zod"; +import { generateUID } from "~/utils/generateUID"; + +import { + createTRPCRouter, + publicProcedure, +} from "~/server/api/trpc"; + +export const authRouter = createTRPCRouter({ + login: publicProcedure + .input(z.object({ email: z.string() })) + .mutation(async ({ ctx, input }) => { + const { data, error } = await ctx.supabase.auth.signInWithOtp({ + email: input.email, + options: { + emailRedirectTo: '/boards', + }, + }) + + console.log({ data }) + console.log({ error }) + + return data; + }) +}); \ No newline at end of file diff --git a/src/server/api/trpc.ts b/src/server/api/trpc.ts index cd27bc29..0f72342a 100644 --- a/src/server/api/trpc.ts +++ b/src/server/api/trpc.ts @@ -13,7 +13,7 @@ import superjson from "superjson"; import { ZodError } from "zod"; import { auth } from "~/server/auth"; -import { db } from "~/server/db"; +import { db, supabase } from "~/server/db"; /** * 1. CONTEXT @@ -44,6 +44,7 @@ export const createInnerTRPCContext = async (opts: CreateContextOptions) => { session, headers: opts.headers, db, + supabase }; };