-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improvement here and there
- Loading branch information
Showing
10 changed files
with
36 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { users } from "@/server/db/schema"; | ||
import { createInsertSchema } from "drizzle-zod"; | ||
import { z } from "zod"; | ||
|
||
export const authSchema = createInsertSchema(users).pick({ | ||
export const authSchema = createInsertSchema(users, { | ||
email: z.string().email(), | ||
password: z | ||
.string() | ||
.min(8, { message: "Password must be at least 8 characters long" }), | ||
}).pick({ | ||
email: true, | ||
password: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
import { createTRPCRouter, publicProcedure } from "@/server/api/trpc"; | ||
import { signIn } from "@/server/auth"; | ||
import { TRPCError } from "@trpc/server"; | ||
import { AuthError } from "next-auth"; | ||
|
||
import { authSchema } from "./auth.input"; | ||
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc"; | ||
|
||
export const authRouter = createTRPCRouter({ | ||
login: publicProcedure.input(authSchema).mutation(async ({ input }) => { | ||
try { | ||
await signIn("credentials", { | ||
email: input.email, | ||
password: input.password, | ||
redirectTo: "/", | ||
}); | ||
} catch (error) { | ||
if (error instanceof AuthError) | ||
throw new TRPCError({ | ||
code: "BAD_REQUEST", | ||
message: error.cause?.err?.message ?? "Oops! Something went wrong!", | ||
}); | ||
} | ||
}), | ||
me: protectedProcedure.query(({ ctx }) => ctx.session.user.id), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters