Skip to content

Contexts and Authenticated Routes deeper in the route tree #2032

Discussion options

You must be logged in to vote

Ok i found a solution that i think is quite sensible so i'll leave it here as an answer for other people.

I ended using Tanstack Query to write the permissions to a query with a static key, and make it update whenever the context is run.
So in the _company_context.tsx:

export function CompanyProvider({ children }: { children: React.ReactNode }) {
...
  const permissions = company?.user_permissions ?? [];
  queryClient.setQueryData(['company_permissions'], () => {
    return permissions;
  });

... 
}
export function hasAccessToCompanyHR() {
  const permissions = queryClient.getQueryData<string[]>(['company_permissions']);
  return permissions?.includes('plant:ReadHR');
}

in the hr.tsx

  l…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@schiller-manuel
Comment options

@SundayPowerEndre
Comment options

@SundayPowerEndre
Comment options

Answer selected by SundayPowerEndre
@SundayPowerEndre
Comment options

@schiller-manuel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants