mirror of
https://github.com/ershisan99/www.git
synced 2025-12-17 05:19:23 +00:00
add social links support
This commit is contained in:
18
src/app/(home)/profile/settings/page.tsx
Normal file
18
src/app/(home)/profile/settings/page.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
41
src/server/api/routers/profile.ts
Normal file
41
src/server/api/routers/profile.ts
Normal 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 }
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user