Migrating to V10 from V9

If someone has some ideas on what I might have screwed up when trying to bump tRPC for this public starter please let me know. https://github.com/chamatt/create-kaol-app/pull/7/files
GitHub
Update server and db dependencies by wezter96 · Pull Request #7 · c...
@chamatt A start of trying to bump the app to using latest version of @tanstack/react-query, prisma and tRPC. If I use interop and don't replace the v9 with the v10 stuff I got it to work b...
sachin
sachin585d ago
if there's any specific problems, let us know in more detail
julius
julius585d ago
you need to update the frontend too
julius
julius585d ago
idk how procedurenames like get-by-id works for the proxy thing, you'd probably need to call them like trpc.post['get-by-id'].useQuery(...) which is kinda whack imo. rename them to be getById for better dx i'd say
sachin
sachin585d ago
julius
julius585d ago
you handle the case and do the renaming???
sachin
sachin585d ago
it concerts everything to camelCase (not really handling the case, it just applies to every procedure)
julius
julius585d ago
awesome
Wezter
Wezter584d ago
ah thanks a lot for the input, I'll hopefully have time to look more at it this weekend. It kinda feels like I've misunderstood how I should update the 'me' query in the authRouter. Before it was a .merge and then a .query and now I only have .query there. https://github.com/chamatt/create-kaol-app/pull/7/files#diff-1737fd1080cbf94128d1b86db71d32f715ff7b0909d374e6de1d71f7a596e3cc
GitHub
Update server and db dependencies by wezter96 · Pull Request #7 · c...
@chamatt A start of trying to bump the app to using latest version of @tanstack/react-query, prisma and tRPC. If I use interop and don't replace the v9 with the v10 stuff I got it to work b...
Wezter
Wezter584d ago
@julius Do you see an issue with how I've implemented the me query and do you possibly have a solution for it? Old authRouter:
export const authRouter = createRouter()
.mutation('signIn', {
input: SignInSchema,
resolve: async ({ input: { email, password } }) => {
return signIn({ email, password })
},
})
.mutation('signUp', {
input: SignUpSchema,
resolve: async ({ input: { email, password } }) => {
const user = await signUp({ email, password })
const token = await createSession(user)
return { token }
},
})
.merge(
'me',
protectedRoute.query('', {
resolve: async ({ ctx }) => {
return ctx.user
},
})
)
export const authRouter = createRouter()
.mutation('signIn', {
input: SignInSchema,
resolve: async ({ input: { email, password } }) => {
return signIn({ email, password })
},
})
.mutation('signUp', {
input: SignUpSchema,
resolve: async ({ input: { email, password } }) => {
const user = await signUp({ email, password })
const token = await createSession(user)
return { token }
},
})
.merge(
'me',
protectedRoute.query('', {
resolve: async ({ ctx }) => {
return ctx.user
},
})
)
` New authRouter:
export const authRouter = t.router({
signIn: t.procedure.input(SignInSchema).mutation((req) => {
const { input } = req

return signIn({ email: input.email, password: input.password })
}),
signUp: t.procedure.input(SignUpSchema).mutation(async (req) => {
const input = req.input

const user = await signUp({ email: input.email, password: input.password })
const token = await createSession(user)
return { token }
}),
//This seems wrong:
me: protectedProcedure.query(async (req) => {
const { ctx } = req
return ctx.user
}),
})
export const authRouter = t.router({
signIn: t.procedure.input(SignInSchema).mutation((req) => {
const { input } = req

return signIn({ email: input.email, password: input.password })
}),
signUp: t.procedure.input(SignUpSchema).mutation(async (req) => {
const input = req.input

const user = await signUp({ email: input.email, password: input.password })
const token = await createSession(user)
return { token }
}),
//This seems wrong:
me: protectedProcedure.query(async (req) => {
const { ctx } = req
return ctx.user
}),
})
julius
julius584d ago
can you also send the protectedProcedure?
julius
julius584d ago
GitHub
create-t3-app/auth-server-utils.ts at next · t3-oss/create-t3-app
Quickest way to start a new web app with full stack typesafety - create-t3-app/auth-server-utils.ts at next · t3-oss/create-t3-app
Wezter
Wezter584d ago
export const protectedRoute = t.middleware(async (req) => {
const { ctx, next } = req
const user = await getUserFromHeader(ctx.headers)
if (!user) {
throw new TRPCError({
message: `Unauthenticated when trying to access ${ctx.req.url}`,
code: 'UNAUTHORIZED',
})
}
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
})

export const protectedProcedure = t.procedure.use(protectedRoute)
export const protectedRoute = t.middleware(async (req) => {
const { ctx, next } = req
const user = await getUserFromHeader(ctx.headers)
if (!user) {
throw new TRPCError({
message: `Unauthenticated when trying to access ${ctx.req.url}`,
code: 'UNAUTHORIZED',
})
}
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
})

export const protectedProcedure = t.procedure.use(protectedRoute)
julius
julius584d ago
im not sure if you can do this
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
try replacing with
return next({
ctx: {
user,
isAdmin: isAdmin(role)
}
});
return next({
ctx: {
user,
isAdmin: isAdmin(role)
}
});
or this should probably also work
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next({ ctx });
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next({ ctx });
Wezter
Wezter584d ago
Did you see an issue with my "me" query in the authrouter as well? It previously had a .merge and now it doesn't 🤔
julius
julius584d ago
merge means it was a router, not sure why you had a router with a query called '' 🤔
Wezter
Wezter584d ago
I didn't create any of this, I'm just trying to bump a starter someone else created. https://github.com/chamatt/create-kaol-app
GitHub
GitHub - chamatt/create-kaol-app: Kaol Stack - Prisma, Expo, Next, ...
Kaol Stack - Prisma, Expo, Next, TRPC, Solito, Tailwind - A monorepo template for a truly universal app - GitHub - chamatt/create-kaol-app: Kaol Stack - Prisma, Expo, Next, TRPC, Solito, Tailwind -...
julius
julius584d ago
it will be called in a similar way now, trpc.auth.me.useQuery()
Wezter
Wezter584d ago
It's the only starter that I've found that has implemented screen sharing well between the web and mobile that also use tRPC and DB integration. I'd probably have gone with the t3 turbo starter otherwise.
More Posts
Authentication broke after bump to v10 from v9Anyone that has any suggestions on what might have caused this? I get the following error when tryiShow a spinner when any mutation is loading?Looking to show an activity spinner in the header of our application whenever a mutation is in flighSharing schemas between server and clientIn a typical nextJs setup, what is the idiomatic way to share zod schemas between frontend and backev10 Migration interop, router doesnt have attributesHi, i've tried to migrate like stated in the docs, these are my routers. Question: Shouldn't appRoutRecommended file structure for next.js?Hey all - using tRPC heavily with next.js and it's great. Our main `[trpc].ts` file is getting huge Unhandled Runtime ErrorTRPCClientErrorCall Stack Function.from node_modules\@trpc\client\dist\TRPCClientError-09b8a26b.esm.js (57:0) transWeird error when running unit test`10.0.0-proxy-beta.5` works just fine, error occurs on `10.0.0-proxy-beta.6` with the introduction oSharing middleware between TRPC serversWe currently have *microservices* REST API's on Cloudflare Workers and I'm thinking about moving thiIs `trpc.withTRPC` for Next supposed to work with pages or only `_app`?I'd love to only have TRPC mount on certain pages of my Next.js app. Is this currently supported?What does the WebSocketHandler do?I'm not sure what this is doing on the background.Are there any example of subscriptions working with react native ?queries and mutations are working pretty well with react native, I'm unable however to get subscriptRecommended way to prefetch client-sideIn react-query, you can do ``` queryClient.prefetchQuery(['todos', input], queryFn) ``` In trpc, IRevalidate API route from procedureHi, is there a way to revalidate a statically generated page from a trpc procedure? https://nextjs.Modifying payload client-side before cachingSay I have a payload that includes something like `category_id` in each of the items returned e.g.: errorFormatter is not being called?Could somebody confirm that this callback is called in the latest version? I call it from server sidResponse headersIs it possible to modify the response headers from server to client?API Response caching not working on vercel ⁉I've followed the instructions in https://trpc.io/docs/v9/caching for API Response caching and it's when throwing a TRPCError, is there a way to include an internal error code ?for the given screenshot, if such error happens I wanna prompt the user to login or something.Websocket connection failed.I'm following the websocket's example and it works fine as it is, however I changed some things and extra json property added after data when consuming a query hook.I have this issue where when consuming a RQ hook there is an extra `json` object that I have to use