ali.mcgill
ali.mcgill
TTCTheo's Typesafe Cult
Created by ali.mcgill on 12/20/2023 in #questions
How to add queryClientConfig to createTRPCNext in t-3 App router
Hi everyone, I am trying to add a default option for tRPC mutations to: "useErrorBoundary: true". In the t-3 Page router I can extend the config() for "api = createTRPCNext<AppRouter> " But I can't find the "config()" in the T-3 App router app. Has anyone else figured this out or is there a better way to set a global default for tRPC mutations/queries in the T-3 App Router app? Thanks
6 replies
TTCTheo's Typesafe Cult
Created by ali.mcgill on 10/30/2023 in #questions
Role control in sub pages
Hi all, I am using a custom hook to check user roles and conditionally render the UI, but I have noticed that the url is not protected, ie if a a url into the browser like http://localhost:3000/some-UI-route/create then the page can be accessed. I have a menu role which restricts access to the "index.tsx" page in the /pages router app but I am not sure how to add a menu role to the "sub" page └-- some-ui/ ├-- index.tsx ├-- edit/ │ └-- [id].tsx └-- create/ └-- index.tsx Is there a nice way to do access role control on the sub route?
2 replies
TTCTheo's Typesafe Cult
Created by ali.mcgill on 10/30/2023 in #questions
roles control on actions
Hi all, I am trying to RBAC actions in a page. I have an array of roles as string for each user. I have a custom hook to check roles:
export default function useCustomRoles(role: string) {
const [ hasRole, setHasRole ] = useState(false)

useEffect(() => {
async function getRoles() {
const res = await http<RolesResonseObject>(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/roles`)
setHasRole(res.roles.includes(role))
}

void getRoles();
}, [role]);

return { hasRole }
}
export default function useCustomRoles(role: string) {
const [ hasRole, setHasRole ] = useState(false)

useEffect(() => {
async function getRoles() {
const res = await http<RolesResonseObject>(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/roles`)
setHasRole(res.roles.includes(role))
}

void getRoles();
}, [role]);

return { hasRole }
}
I am then using the hook to conditonally render buttons, etc in the UI:
const { hasRole: hasCreatePermission} = useCustomRoles("some-role-here")
const { hasRole: hasCreatePermission} = useCustomRoles("some-role-here")
Does this seem like a good implementation, is there a better way to do it?
4 replies
TTCTheo's Typesafe Cult
Created by ali.mcgill on 4/12/2023 in #questions
Linking 2+ T-3 apps together. Any advice for linking up two repos together to make a composite app?
I have an application shell app and I want to bring in an app that handles "user-settings" (each app has its own pages and api routes with tRPC). I have have tried git sub-modules but that caused conflicts between both apps. Is there a good way to combine the two apps together to use one URL for access. And use the Layout from the application shell with the pages from "user-settings" app?
3 replies