Where does the context comes from?

Hi, I’m following the Cookbook for Role-based Access Control (RBAC) and came across the following codes:

export const requireAuth = ({ roles } = {}) => {
  if (!context.currentUser) {
    throw new AuthenticationError("You don't have permission to do that.")
  }

I have difficulty in understanding where does the context comes from, appreciate any help.:pray::grinning:

Context is set as a global variable, so you can access it throughout the API code as you please :slight_smile:

1 Like

HI @andrewlamyw - as @3nvy noted, you can see its implementation here:

And the reason currentUser is available is because this handler sets it (line 44).

and it’s use the the GraphQLHandler:

in createContextHandler:

and the reason currentUser is available is because it is set on this context at line 44.

1 Like