Merge pull request #10 from payloadcms/feature/allow-admin-verify
This commit is contained in:
@@ -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[];
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user