Protects the `/api/access` endpoint behind authentication and sanitizes the result, making it more secure and significantly smaller. To do this: 1. The `permission` keyword is completely omitted from the result 2. Only _truthy_ access results are returned 3. All nested permissions are consolidated when possible --------- Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com> Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com> Co-authored-by: James <james@trbl.design>
29 lines
573 B
TypeScript
29 lines
573 B
TypeScript
'use client'
|
|
|
|
import type { SanitizedPermissions } from 'payload'
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
import { useAuth } from '../../providers/Auth/index.js'
|
|
|
|
/**
|
|
* The Auth Provider wraps the entire app
|
|
* but each page has specific permissions
|
|
*
|
|
* i.e. access control on documents/fields on a document
|
|
*/
|
|
|
|
type Props = {
|
|
permissions: SanitizedPermissions
|
|
}
|
|
|
|
export function HydrateAuthProvider({ permissions }: Props) {
|
|
const { setPermissions } = useAuth()
|
|
|
|
useEffect(() => {
|
|
setPermissions(permissions)
|
|
}, [permissions, setPermissions])
|
|
|
|
return null
|
|
}
|