I am trying to implement permissions to the RBAC model of dbAuth and use them on the web side. I have added new functionality to the auth.ts file where hasRole is implemented and added my code for hasPermission. Sadly I don’t have access to it. So I went to explore where I get hasRole from anyway.
In my client side component I do:
import { useAuth } from 'web/src/auth'
...
const { currentUser, hasPermission } = useAuth()
But that fails because hasPermission is not part of useAuth. So I found where useAuth is created and I see we’re also declaring useHasRole and useCurrentUser in @redwoodjs/auth-dbauth-web.
export declare function createAuth(dbAuthClient: ReturnType<typeof createDbAuthClient>, customProviderHooks?: {
useCurrentUser?: () => Promise<CurrentUser>;
useHasRole?: (currentUser: CurrentUser | null) => (rolesToCheck: string | string[]) => boolean;
}): {
AuthContext: import("react").Context<import("@redwoodjs/auth").AuthContextInterface<string, LoginAttributes, any, unknown, boolean, SignupAttributes, any, any, ResetPasswordAttributes, any, any, import("./webAuthn").default> | undefined>;
AuthProvider: ({ children, skipFetchCurrentUser, }: import("@redwoodjs/auth/dist/AuthProvider/AuthProvider").AuthProviderProps) => import("react").JSX.Element;
useAuth: () => import("@redwoodjs/auth").AuthContextInterface<string, LoginAttributes, any, unknown, boolean, SignupAttributes, any, any, ResetPasswordAttributes, any, any, import("./webAuthn").default>;
};
I cannot edit the node_modules dbAuth.d.ts file so is the only way to add additional functionality to the auth.ts file to amend the web/src/auth.ts file?
import { createDbAuthClient, createAuth } from '@redwoodjs/auth-dbauth-web'
const dbAuthClient = createDbAuthClient()
export const { AuthProvider, useAuth, +include hasPermission+ } = createAuth(dbAuthClient)