Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

RBAC Cookbook needs to be updated to use Auth Validation Directives #812

Open
dthyresson opened this issue Oct 1, 2021 · 0 comments
Open
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@dthyresson
Copy link
Contributor

dthyresson commented Oct 1, 2021

See: https://redwoodjs.com/cookbook/role-based-access-control-rbac

For v0.37, the way roles re checked has moved into SDLs.

All the examples here need updating.

For example:

requireAuth should not be in the service, but declared on the mutation.

import { db } from 'src/lib/db'
import { requireAuth } from 'src/lib/auth'

const CREATE_POST_ROLES = ['admin', 'author', 'publisher']

export const createPost = ({ input }) => {
  requireAuth({ role: CREATE_POST_ROLES })

  return db.post.create({
    data: {
      ...input,
      authorId: context.currentUser.sub,
      publisherId: context.currentUser.sub,
    },
  })
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant