* chore: converts dynamic imports to esm require * chore: adjusts require and import usage * chore: reverts bin script change * chore: adjust dataloaded tests to use slate editor * fix: converts custom auth strategy * chore: fixes to form builder int test config * chore: adjusts plugin-stripe and int tests --------- Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
82 lines
1.7 KiB
TypeScript
82 lines
1.7 KiB
TypeScript
import type { AuthStrategyFunction } from 'payload/auth.js'
|
|
|
|
import { buildConfigWithDefaults } from '../../buildConfigWithDefaults.js'
|
|
import { usersSlug } from './shared.js'
|
|
|
|
export const strategyName = 'test-local'
|
|
|
|
const customAuthenticationStrategy: AuthStrategyFunction = async ({ headers, payload }) => {
|
|
const usersQuery = await payload.find({
|
|
collection: usersSlug,
|
|
where: {
|
|
code: {
|
|
equals: headers.get('code'),
|
|
},
|
|
secret: {
|
|
equals: headers.get('secret'),
|
|
},
|
|
},
|
|
})
|
|
|
|
const user = usersQuery.docs[0] || null
|
|
if (!user) return null
|
|
|
|
return {
|
|
...user,
|
|
_strategy: `${usersSlug}-${strategyName}`,
|
|
collection: usersSlug,
|
|
}
|
|
}
|
|
|
|
export default buildConfigWithDefaults({
|
|
admin: {
|
|
user: 'users',
|
|
},
|
|
collections: [
|
|
{
|
|
slug: usersSlug,
|
|
access: {
|
|
create: () => true,
|
|
},
|
|
auth: {
|
|
disableLocalStrategy: true,
|
|
strategies: [
|
|
{
|
|
name: strategyName,
|
|
authenticate: customAuthenticationStrategy,
|
|
},
|
|
],
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'code',
|
|
type: 'text',
|
|
index: true,
|
|
label: 'Code',
|
|
unique: true,
|
|
},
|
|
{
|
|
name: 'secret',
|
|
type: 'text',
|
|
label: 'Secret',
|
|
},
|
|
{
|
|
name: 'name',
|
|
type: 'text',
|
|
label: 'Name',
|
|
},
|
|
{
|
|
name: 'roles',
|
|
type: 'select',
|
|
defaultValue: 'user',
|
|
hasMany: true,
|
|
label: 'Role',
|
|
options: ['admin', 'editor', 'moderator', 'user', 'viewer'],
|
|
required: true,
|
|
saveToJWT: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|