Catch non-arrays
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
tobias 2024-07-05 22:42:32 +02:00
parent 199234a7e2
commit a27c335113
3 changed files with 20 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}