add social links support

This commit is contained in:
2025-06-21 15:01:22 +02:00
parent 86014e261b
commit 3db5de8c26
2 changed files with 59 additions and 0 deletions

View File

@@ -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 (
<HydrateClient>
<ProfileSettingsPageClient userId={session.user.discord_id} />
</HydrateClient>
)
}

View File

@@ -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 }
}),
})