feat - new changes
This commit is contained in:
parent
96ebac5547
commit
974337af2b
@ -1,9 +1,14 @@
|
||||
import { redirect } from "@tanstack/react-router"
|
||||
import { createServerFn } from "@tanstack/react-start"
|
||||
import { eq } from "drizzle-orm"
|
||||
import { db } from "@/integrations/drizzle"
|
||||
import { profiles, users } from "@/integrations/drizzle/db/schema"
|
||||
import { getSupabaseServerClient } from "@/integrations/supabase/supabase"
|
||||
import { loginFormSchema, profileFormSchema, signupFormSchema } from "../validation/user"
|
||||
import {
|
||||
loginFormSchema,
|
||||
profileFormSchema,
|
||||
signupFormSchema
|
||||
} from "../validation/user"
|
||||
|
||||
export const getUser = createServerFn().handler(async () => {
|
||||
const supabase = getSupabaseServerClient()
|
||||
@ -85,7 +90,6 @@ export const signupUser = createServerFn({ method: "POST" })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export const getAllUsers = createServerFn().handler(async () => {
|
||||
const response = await db.select().from(users)
|
||||
return response
|
||||
@ -94,17 +98,18 @@ export const getAllUsers = createServerFn().handler(async () => {
|
||||
export const createProfile = createServerFn({ method: "POST" })
|
||||
.validator(profileFormSchema)
|
||||
.handler(async ({ data }) => {
|
||||
await db.insert(profiles).values(data).returning();
|
||||
await db.insert(profiles).values(data).returning()
|
||||
})
|
||||
|
||||
export const getProfile = createServerFn().handler(async (data) => {
|
||||
const { id } = data;
|
||||
export const getProfile = createServerFn({ method: "POST" })
|
||||
.validator((data: { id: string }) => data)
|
||||
.handler(async ({ data }) => {
|
||||
const { id } = data
|
||||
const response = await db
|
||||
.select()
|
||||
.from(profiles)
|
||||
.where(eq(profiles.id, id))
|
||||
.limit(1)
|
||||
|
||||
const response = await db
|
||||
.select()
|
||||
.from(profiles)
|
||||
.where(eq(profiles.id, id))
|
||||
.limit(1);
|
||||
|
||||
return response[0] ?? null;
|
||||
});
|
||||
return response[0] ?? null
|
||||
})
|
||||
|
||||
@ -12,7 +12,5 @@ export const signupFormSchema = z.object({
|
||||
})
|
||||
|
||||
export const profileFormSchema= z.object({
|
||||
id: z.uuid(),
|
||||
firstName: z.string(),
|
||||
lastName: z.string().optional()
|
||||
id: z.uuid()
|
||||
})
|
||||
@ -1,4 +1,4 @@
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { getProfile } from "@/lib/server/user"
|
||||
|
||||
export const Route = createFileRoute("/_authed")({
|
||||
@ -8,10 +8,11 @@ export const Route = createFileRoute("/_authed")({
|
||||
// TODO: Redirect to login page
|
||||
}
|
||||
},
|
||||
loader: (context) => {
|
||||
console.log(context);
|
||||
const profile = getProfile()
|
||||
console.log(profile)
|
||||
loader: ({context: {queryClient, user}} ) => {
|
||||
queryClient.ensureQueryData({
|
||||
queryKey: ["profile"],
|
||||
queryFn: () => getProfile({ data: { id: user?.id as string } })
|
||||
})
|
||||
},
|
||||
errorComponent: ({ error }) => {
|
||||
if (error.message === "Not authenticated") {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Button } from "@heroui/react"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { getAllUsers } from "@/lib/server/user"
|
||||
import { getAllUsers, getProfile } from "@/lib/server/user"
|
||||
|
||||
export const Route = createFileRoute("/_authed/post")({
|
||||
component: RouteComponent
|
||||
@ -9,7 +9,7 @@ export const Route = createFileRoute("/_authed/post")({
|
||||
|
||||
function RouteComponent() {
|
||||
const navigate = Route.useNavigate()
|
||||
|
||||
const { user } = Route.useRouteContext()
|
||||
const { data } = useQuery({
|
||||
queryKey: ["users"],
|
||||
queryFn: async () => {
|
||||
@ -17,7 +17,15 @@ function RouteComponent() {
|
||||
}
|
||||
})
|
||||
|
||||
const { data: profile } = useQuery({
|
||||
queryKey: ["profile"],
|
||||
queryFn: async () => {
|
||||
return getProfile({ data: { id: user?.id as string } })
|
||||
}
|
||||
})
|
||||
|
||||
console.log(data)
|
||||
console.log(profile)
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user