Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type errors in lib/auth.ts when using a non-RBAC dbAuth setup #5856

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ import { getCurrentUser } from '../../../api/src/lib/auth'
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T
export type InferredCurrentUser = ThenArg<ReturnType<typeof getCurrentUser>>

type UndefinedRoles = {
/**
* ⚠️ Heads-Up: This is undefined unless roles key is returned from {@link getCurrentUser()}
*
* You may take a look at https://redwoodjs.com/docs/tutorial/chapter7/rbac for a tutorial on
* how to add fully-fledged RBAC (Role-based Access Control) to your database model.
*/
roles?: unknown | unknown[]
}

type Overwrite<T, U> = Omit<T, keyof U> & U

declare module '@redwoodjs/graphql-server' {
interface GlobalContext {
currentUser?: InferredCurrentUser
currentUser?: Overwrite<UndefinedRoles, InferredCurrentUser>
}
}

Expand Down