feat: setup auth
This commit is contained in:
@@ -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 (
|
||||
<Formik
|
||||
initialValues={{
|
||||
email: "",
|
||||
}}
|
||||
onSubmit={async (values: FormValues) => {
|
||||
await signIn("email", {
|
||||
onSubmit={(values: FormValues) => {
|
||||
login.mutate({
|
||||
email: values.email,
|
||||
callbackUrl: "/boards",
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -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,
|
||||
|
||||
25
src/server/api/routers/auth.ts
Normal file
25
src/server/api/routers/auth.ts
Normal file
@@ -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;
|
||||
})
|
||||
});
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user