diff --git a/src/app/(home)/profile/settings/page.tsx b/src/app/(home)/profile/settings/page.tsx new file mode 100644 index 0000000..8d6662a --- /dev/null +++ b/src/app/(home)/profile/settings/page.tsx @@ -0,0 +1,18 @@ +import { ProfileSettingsPageClient } from '@/app/(home)/profile/settings/page-client' +import { auth } from '@/server/auth' +import { HydrateClient, api } from '@/trpc/server' +import { SessionProvider } from 'next-auth/react' +import { redirect } from 'next/navigation' + +export default async function ProfileSettingsPage() { + const session = await auth() + if (!session) { + redirect('/') + } + await Promise.all([api.profile.getSocialLinks.prefetch()]) + return ( + + + + ) +} diff --git a/src/server/api/routers/profile.ts b/src/server/api/routers/profile.ts new file mode 100644 index 0000000..5f8dc45 --- /dev/null +++ b/src/server/api/routers/profile.ts @@ -0,0 +1,41 @@ +import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc' +import { db } from '@/server/db' +import { users } from '@/server/db/schema' +import { z } from 'zod' +import { eq } from 'drizzle-orm' + +export const profileRouter = createTRPCRouter({ + getSocialLinks: protectedProcedure + .query(async ({ ctx }) => { + const user = await db.query.users.findFirst({ + where: eq(users.id, ctx.session.user.id), + columns: { + twitch_url: true, + youtube_url: true, + }, + }) + return { + twitch_url: user?.twitch_url || null, + youtube_url: user?.youtube_url || null, + } + }), + + updateSocialLinks: protectedProcedure + .input( + z.object({ + twitch_url: z.string().url().nullable(), + youtube_url: z.string().url().nullable(), + }) + ) + .mutation(async ({ ctx, input }) => { + await db + .update(users) + .set({ + twitch_url: input.twitch_url, + youtube_url: input.youtube_url, + }) + .where(eq(users.id, ctx.session.user.id)) + + return { success: true } + }), +}) \ No newline at end of file