From a6a23e3b154802e5ec874760b3d3e44e90f56e7c Mon Sep 17 00:00:00 2001 From: James Date: Sat, 16 Jan 2021 18:23:26 -0500 Subject: [PATCH 1/3] feat: allows admins to autoverify via admin --- src/admin/components/views/collections/Edit/Auth/index.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/admin/components/views/collections/Edit/Auth/index.tsx b/src/admin/components/views/collections/Edit/Auth/index.tsx index 703483b3f2..3ed272f095 100644 --- a/src/admin/components/views/collections/Edit/Auth/index.tsx +++ b/src/admin/components/views/collections/Edit/Auth/index.tsx @@ -114,9 +114,6 @@ const Auth: React.FC = (props) => { )} From 2139eb410f8c95505ef7b90e35a099b0955d4e12 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 22 Jan 2021 17:13:27 -0500 Subject: [PATCH 2/3] feat: auto-removes verificationToken upon manual user verify --- docs/hooks/fields.mdx | 4 ++-- .../baseFields/baseVerificationFields.ts | 19 ++++++++++++++++++- src/fields/hookPromise.ts | 6 ++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/hooks/fields.mdx b/docs/hooks/fields.mdx index ab4a0e2781..4de353eac7 100644 --- a/docs/hooks/fields.mdx +++ b/docs/hooks/fields.mdx @@ -44,7 +44,7 @@ Example field configuration: ## Arguments and return values -All field-level hooks are formatted to accept the same arguments, although some may be `undefined` based on which field hook you are utilizing. +All field-level hooks are formatted to accept the same arguments, although some arguments may be `undefined` based on which field hook you are utilizing. Tip:
@@ -65,7 +65,7 @@ Field Hooks receive one `args` argument that contains the following properties: #### Return value -All field hooks can optionally modify the return value of the field before the operation continues. Field Hooks may optionally return the value that should be used within the field. +Field hooks **must** return the intended value for the field to be used in the operation. You can modify the return value of the field before the operation continues, or simply send the `value` that you receive through the hook's argument. If you return `undefined` within a `beforeChange` or `beforeValidate` hook, the property will be unset from its document. Important
diff --git a/src/fields/baseFields/baseVerificationFields.ts b/src/fields/baseFields/baseVerificationFields.ts index a4ec730411..253334305a 100644 --- a/src/fields/baseFields/baseVerificationFields.ts +++ b/src/fields/baseFields/baseVerificationFields.ts @@ -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[]; diff --git a/src/fields/hookPromise.ts b/src/fields/hookPromise.ts index bce1372753..7ee3b64858 100644 --- a/src/fields/hookPromise.ts +++ b/src/fields/hookPromise.ts @@ -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()); } }; From dd3181805178b90200c52dcfa6743fb0122d0942 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 22 Jan 2021 17:15:39 -0500 Subject: [PATCH 3/3] docs: typo in graphql --- docs/graphql/overview.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/graphql/overview.mdx b/docs/graphql/overview.mdx index 04b1c77677..ec8d9f8b8a 100644 --- a/docs/graphql/overview.mdx +++ b/docs/graphql/overview.mdx @@ -17,7 +17,7 @@ The labels you provide for your Collections and Globals are used to name the Gra Everything that can be done to a Collection via the REST or Local API can be done with GraphQL (outside of uploading files, which is REST-only). If you have a collection as follows: ```js -const Post = { +const PublicUser = { slug: 'public-users', auth: true, // Auth is enabled labels: {