diff --git a/server/src/routers/mentorship.ts b/server/src/routers/mentorship.ts index 561d22dc..5137c5d0 100644 --- a/server/src/routers/mentorship.ts +++ b/server/src/routers/mentorship.ts @@ -32,10 +32,14 @@ const createMentor = protectedProcedure tags: ["Mentorship"], }, }) - .mutation(({ input }) => + .mutation(({ input, ctx }) => withErrorHandling("", async () => { - log.debug({ userId: input.userId }, "createMentor"); - return await mentorshipService.createMentor(input); + const userId = ctx.auth.user.id; + log.debug({ userId }, "createMentor"); + return await mentorshipService.createMentor({ + ...input, + userId, + }); }), ); @@ -50,9 +54,12 @@ const createMentee = protectedProcedure tags: ["Mentorship"], }, }) - .mutation(({ input }) => + .mutation(({ input, ctx }) => withErrorHandling("createMentee", async () => { - return await mentorshipService.createMentee(input); + return await mentorshipService.createMentee({ + ...input, + userId: ctx.auth.user.id, + }); }), ); diff --git a/server/src/types/mentee-types.ts b/server/src/types/mentee-types.ts index 745b4f1e..c09b8368 100644 --- a/server/src/types/mentee-types.ts +++ b/server/src/types/mentee-types.ts @@ -24,7 +24,6 @@ export const menteeSchema = z.object({ export type MenteeSchema = z.infer; export const createMenteeInputSchema = z.object({ - userId: z.string(), learningGoals: z.string().optional(), experienceLevel: z.string().optional(), preferredMentorType: z.string().optional(), @@ -59,7 +58,9 @@ export const getMenteesByUserInputSchema = z.object({ userId: z.string(), }); -export type CreateMenteeInput = z.infer; +export type CreateMenteeInput = z.infer & { + userId: string; +}; export type UpdateMenteeInput = z.infer; export type GetMenteeInput = z.infer; export type GetMenteesByUserInput = z.infer; diff --git a/server/src/types/mentor-types.ts b/server/src/types/mentor-types.ts index 7258ab48..634b8a9e 100644 --- a/server/src/types/mentor-types.ts +++ b/server/src/types/mentor-types.ts @@ -38,7 +38,6 @@ export const mentorSchema = z.object({ export type MentorSchema = z.infer; export const createMentorInputSchema = z.object({ - userId: z.string(), mentorshipPreferences: z.string().optional(), yearsOfService: z.number().int().nonnegative().optional(), eligibilityData: z.record(z.string(), z.unknown()).nullish(), @@ -70,7 +69,9 @@ export const createMentorInputSchema = z.object({ hoursPerMonthCommitment: z.number().int().positive().optional(), }); -export type CreateMentorInput = z.infer; +export type CreateMentorInput = z.infer & { + userId: string; +}; export const createMentorOutputSchema = z.object({ mentorId: z.number(), diff --git a/web/src/app/mentorship/apply/mentee/page.tsx b/web/src/app/mentorship/apply/mentee/page.tsx index ae4c8fa0..846fecdd 100644 --- a/web/src/app/mentorship/apply/mentee/page.tsx +++ b/web/src/app/mentorship/apply/mentee/page.tsx @@ -15,7 +15,6 @@ import { DropzoneContent, DropzoneEmptyState, } from "@/components/ui/shadcn-io/dropzone"; -import { authClient } from "@/lib/auth-client"; import { useTRPC, useTRPCClient } from "@/lib/trpc"; type ResumeState = null | { @@ -66,8 +65,6 @@ export default function MentorshipApplyMenteePage() { const queryClient = useQueryClient(); const router = useRouter(); const searchParams = useSearchParams(); - const { data: sessionData } = authClient.useSession(); - const userId = sessionData?.user?.id ?? null; const backHref = useMemo( () => searchParams.get("from") === "dashboard" @@ -168,11 +165,6 @@ export default function MentorshipApplyMenteePage() { }, [resume, trpcClient]); const handleSubmit = async () => { - if (!userId) { - setFormError("You must be logged in to submit this application."); - return; - } - // Block submit if resume is in a bad state if (resume?.status === "uploading") { setFormError("Please wait for the resume upload to complete."); @@ -207,7 +199,6 @@ export default function MentorshipApplyMenteePage() { })(); await createMentee.mutateAsync({ - userId, resumeFileId: resume?.status === "uploaded" ? resume.fileId : undefined, personalInterests: selectedInterests.length > 0 diff --git a/web/src/app/mentorship/apply/mentor/page.tsx b/web/src/app/mentorship/apply/mentor/page.tsx index 552524aa..54b675f7 100644 --- a/web/src/app/mentorship/apply/mentor/page.tsx +++ b/web/src/app/mentorship/apply/mentor/page.tsx @@ -15,7 +15,6 @@ import { DropzoneContent, DropzoneEmptyState, } from "@/components/ui/shadcn-io/dropzone"; -import { authClient } from "@/lib/auth-client"; import { useTRPCClient } from "@/lib/trpc"; type ResumeState = null | { @@ -29,8 +28,6 @@ export default function MentorshipApplyMentorPage() { const trpcClient = useTRPCClient(); const router = useRouter(); const searchParams = useSearchParams(); - const { data: sessionData } = authClient.useSession(); - const userId = sessionData?.user?.id ?? null; const backHref = useMemo( () => searchParams.get("from") === "dashboard" @@ -134,11 +131,6 @@ export default function MentorshipApplyMentorPage() { }, [resume, isSubmitted, trpcClient]); const handleSubmit = useCallback(async () => { - if (!userId) { - setFormError("You must be logged in to submit this application."); - return; - } - setFormError(null); setIsSubmitting(true); @@ -197,7 +189,6 @@ export default function MentorshipApplyMentorPage() { })(); await createMentor.mutateAsync({ - userId, resumeFileId: resume?.status === "uploaded" ? resume.fileId : undefined, strengths: selectedQualities, personalInterests: @@ -234,7 +225,6 @@ export default function MentorshipApplyMentorPage() { setIsSubmitting(false); } }, [ - userId, resume, selectedQualities, selectedInterests,