Merge pull request #10 from payloadcms/feature/allow-admin-verify

This commit is contained in:
Elliot DeNolf
2021-01-23 15:54:47 -05:00
committed by GitHub
5 changed files with 23 additions and 11 deletions

View File

@@ -1,4 +1,16 @@
import { Field } from '../config/types';
import { Field, FieldHook } from '../config/types';
const autoRemoveVerificationToken: FieldHook = ({ originalDoc, data, value }) => {
// If a user manually sets `_verified` to true,
// and it was `false`, set _verificationToken to `undefined`.
// This is useful because the admin panel
// allows users to set `_verified` to true manually
if (data?._verified === true && originalDoc?._verified === false) {
return undefined;
}
return value;
};
export default [
{
@@ -17,5 +29,10 @@ export default [
name: '_verificationToken',
type: 'text',
hidden: true,
hooks: {
beforeChange: [
autoRemoveVerificationToken,
],
},
},
] as Field[];

View File

@@ -33,11 +33,9 @@ const hookPromise = async ({
data: fullData,
operation,
req,
}) || data[field.name];
});
if (hookedValue !== undefined) {
resultingData[field.name] = hookedValue;
}
resultingData[field.name] = hookedValue;
}, Promise.resolve());
}
};