ibamsey
ibamsey
TTCTheo's Typesafe Cult
Created by ibamsey on 5/23/2023 in #questions
Fine Grained Authorisation
Can people indicate the best approach to fine grained authorisation within a T3 stack app. This means for each authenticated user, we have an Access Control List (ACL) which contains all the fine grain privileges a user has. Most examples are just trivial, e.g. two roles Admin and User. In real world business apps, we construct roles from many fine grained privileges. For each use case we need to control the UI elements and API calls which are allowed. This means grey-outs or removal of UI element, and restricting api calls. The API (which may be via GraphQL at this time) already checks the ACL and throws errors as appropriate. As we move to tRPC we will need the same. We are using NextAuth. What libraries or approaches can be recommended for implementing FGA in the T3 world?
1 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 4/14/2023 in #questions
Turborepo and importing packages
I'm trying to get started with monorepos and am using turborepo in the toolchain. I have a git repository that contains some Next pages/api/components which I want to use in my main application (the one in the monorepo). Somehow I'm expecting to specify my git repo somewhat and then the code to by pulled into the monorepo. This would allow me to maintain common elements used in lots of applications (each in thier own monorepo) and have these included in the main app build. My question here is what is the workflow? Do we simple run git pull on the packages in some build script? what's the right way to arrange the importing of packages into a monorepo?
1 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 3/20/2023 in #questions
<suspense>
Can the React suspense features be used with tRPC ?
6 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 2/22/2023 in #questions
T3 API routes and GraphQL
We're building new React/Next front end code. We need to access our legacy Java business layer. In future we expect to build new business logic in Typescript accessing DB with Prisma. So we need a mix of T3/primsa and GraphQL (or OpenAPI / Rest). What is the best code architecture. I am thinking we create tRPC server side routes where we check authorisation etc. then call our GraphQL or access other databases via Prisma. Does this make sense, or this there a best way to mix?
2 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 11/22/2022 in #questions
tRPC and REST
We're considering building tRPC Nextjs base systems which pull data from Strapi via REST calls. So, instead of using getServerSideProps, I am thinking we will would create a router and define procedures which each make appropriate REST calls to Strapi. Is this the right approach? Your comments and thoughts would be appreciated. Thanks!
15 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 11/10/2022 in #questions
Programmatically determine which field to update in a Prisma mutation
I want to update a specific field in my database. I'm passing the id of the record to update, the name of the field and the new value for this field, into my router to the chgField procedure. Can this be done with some syntax like that shown in * input.field: input.nu * below , if so, help on the syntax here would be great (this doesn't work).
export const peopleRouter = router({
chgField: publicProcedure
.input(
z.object({
idx: z.string(),
field: z.string(),
nu: z.string(),
}),
)
.mutation(({ ctx , input }) => {
return ctx.prisma.user.update({
data: {
*input.field: input.nu*
},
where: {
id: input.idx
}
});
}),
});
export const peopleRouter = router({
chgField: publicProcedure
.input(
z.object({
idx: z.string(),
field: z.string(),
nu: z.string(),
}),
)
.mutation(({ ctx , input }) => {
return ctx.prisma.user.update({
data: {
*input.field: input.nu*
},
where: {
id: input.idx
}
});
}),
});
I sense it might not be possible this way!
8 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 11/9/2022 in #questions
Ok, so what am I missing
I get a
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. when the changeFeildValue handler is fired.
import React from "react"; import { useRouter } from 'next/router' import { trpc } from "../../utils/trpc"; import Profile from "../../components/profile";
export default function Party() {
const { query } = useRouter(); const f = ${query.id} if(!query.id) return const { data: uzer, refetch, isLoading, } = trpc.people.getPersonById.useQuery({id: query.id.toString()},{ refetchInterval: false, refetchOnReconnect: false, refetchOnWindowFocus: false, });
const changeFeildValue = (idx: string, newVal: string) => {
trpc.people.useMutation.useQuery({idx: idx, nu: newVal } ); } if(!uzer) return (<div>load</div>) return <Profile user={uzer} handleChange={changeFeildValue}></Profile> ) }
19 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 11/7/2022 in #questions
tRPC query syntax
Can someone please help a Noob here. I'm struggling to work out how to modify the create-T3-app code below for a findUnique or findFirst query where I will need both {ctx} and {input}. Apologies, I'm new to TypeScript ! import { z } from "zod"; import { router, publicProcedure } from "../trpc"; export const exampleRouter = router({ hello: publicProcedure .input(z.object({ text: z.string().nullish() }).nullish()) .query(({ input }) => { return { greeting: Hello ${input?.text ?? "world"}, }; }), getAll: publicProcedure.query(({ ctx }) => { return ctx.prisma.example.findMany(); }), });
9 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 10/22/2022 in #questions
tRPC basics - returning an array
I suspect this is my ignorance of typescript. I am just not getting anywhere with this tRPC set up. I just want to return an array, but my query result is empty. Router const partyList = [ { firstName: 'joe', lastName: 'linsley', age: 24 }, { firstName: 'bill', lastName: 'smith', age: 40 }, ] export const userRouter = router({ partyRoleRouter: publicProcedure.query(() => { return partyList; }), }); Page const peps = trpc.party.partyRoleRouter.useQuery(); console.log("Peps ",peps.data) if (!peps.data) return <div>Loading...</div>; Question peps is always undefined. Why??? how do I get the array of people in partyList?
4 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 10/12/2022 in #questions
Conditional render - UI with mode
Can anyone point to a repo / project which exemplifies a React code pattern for a UI which has 2 modes. For example, admin user and user. In such a UI the admin can configure the things within the UI, and these are seen by the user. Here the UI is very similar for both roles, but the behaviour and controls are different. Simply filling the code with conditions to render / not render various controls is too simplistic, messy and hard to maintain. What I'm looking for is something like a page structure into which two sets of behaviours are imposed.
1 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 10/11/2022 in #questions
Content Repositories - Please not WP!
We need a content repo for users to create structured content which gets used in an t3 app. Why build this when there should be good solutions out there. What's your experience in accessing and using them in your t3 application?
5 replies
TTCTheo's Typesafe Cult
Created by ibamsey on 10/4/2022 in #questions
Multi-tenant - easy no?
Am I missing something in plain sight ? Is there a well trodden path / mature framework within typical Next.js Prisma Vercel stacks for implementing a solid multi-tenanted SaaS ? Or is it that everyone rolls their own.
88 replies