This commit is contained in:
parent
199234a7e2
commit
a27c335113
@ -2,6 +2,10 @@ import { Access } from 'payload/types'
|
||||
import type { User } from 'types/payload-types'
|
||||
|
||||
export const isAdmin = ({ req: { user } }: any) => {
|
||||
if (!user.roles) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (user && user.roles?.includes('admin')) {
|
||||
return true
|
||||
}
|
||||
@ -10,6 +14,10 @@ export const isAdmin = ({ req: { user } }: any) => {
|
||||
}
|
||||
|
||||
export const isAdminOrCreatedBy = ({ req: { user } }: any) => {
|
||||
if (user.role) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (user && user.role === 'admin') {
|
||||
return true
|
||||
}
|
||||
@ -27,6 +35,10 @@ export const isAdminOrCreatedBy = ({ req: { user } }: any) => {
|
||||
|
||||
export const isAdminOrSelf = ({ req: { user } }: any) => {
|
||||
if (user) {
|
||||
if (!user.roles) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (user.roles?.includes('admin')) {
|
||||
return true
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ import { Access, FieldAccess } from 'payload/types'
|
||||
import type { User } from 'types/payload-types'
|
||||
|
||||
export const isEditor = ({ req: { user } }: any) => {
|
||||
if (!user.roles) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (user && user?.roles?.some((role: string) => ['editor', 'admin'].includes(role))) {
|
||||
return true
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ import { Access, FieldAccess } from 'payload/types'
|
||||
import type { User } from 'types/payload-types'
|
||||
|
||||
export const isUser = ({ req: { user } }: any) => {
|
||||
if (!user.roles) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (user && user?.roles?.some((role: string) => ['user', 'editor', 'admin'].includes(role))) {
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user