Files
payload/src/fields/baseFields/baseVerificationFields.ts
James Mikrut a2e57b09f2 fix: misc responsive improvements, date clipping in sidebar (#165), express-fileupload schema validation (#180)
* fix: misc responsive improvements
* fix: date clipping in sidebar
* fix: revises popup
* fix: admin _verified field not displaying proper field value
* fix: properly typed express-fileupload config options
2021-05-16 13:04:29 -04:00

44 lines
985 B
TypeScript

import { Field, FieldHook } from '../config/types';
const autoRemoveVerificationToken: FieldHook = ({ originalDoc, data, value, operation }) => {
// If a user manually sets `_verified` to true,
// and it was `false`, set _verificationToken to `null`.
// This is useful because the admin panel
// allows users to set `_verified` to true manually
if (operation === 'update') {
if (data?._verified === true && originalDoc?._verified === false) {
return null;
}
}
return value;
};
export default [
{
name: '_verified',
type: 'checkbox',
access: {
create: () => false,
update: ({ req: { user } }) => Boolean(user),
read: ({ req: { user } }) => Boolean(user),
},
admin: {
components: {
Field: () => null,
},
},
},
{
name: '_verificationToken',
type: 'text',
hidden: true,
hooks: {
beforeChange: [
autoRemoveVerificationToken,
],
},
},
] as Field[];