Skip to content

Ability to customise user registration mutation and validation of user fields #113

@Stalex89

Description

@Stalex89

Hello,

I have a specific scenario for a user registration process. In Craft I have an entry type which contains field with activation code.
On the frontend (not a twig template but decoupled frontend, so no twig solution applicable) I have a user register page with user registration form. In one of the fields in the form user should enter the activation code. Before the user is registered I need a way to validate this field if the code matches the code from one of entries. If the activation code provided by user is matching none of codes from entries, it should throw a validation error.

So basically I need the following registration flow:

  1. User goes to /register page on the decoupled frontend
  2. User fills in email, password, confirm_password and activation code in the registration form
  3. User presses "register button"
  4. Mutation from the graphql-authentication plugin is called with (username, password, activation_code [String]!) params
  5. Plugin validates activation_code by checking if there is an entry with the matching code exists.
  6. If code activation_code validation failed, the error is thrown with the message "Invalid activation code"
  7. If code activation_code validation succeed, the user is registered and respective entry is added to a user custom field

As I read from documentation it is possible to provide additional values in register mutation for user custom fields, but there is no hook that can be used to modify user registration/validation logic in mutation. Also it's not quite suitable for my case as I need either to add entry ID field to the User (I would prefer to add an entry relation itself and not the id text field), or pass the entry id directly from the frontend (which is not suitable because user should know activation code but not an entry id).

Can you pls tell if there's a way to extend/modify the user register mutation inside the plugin to handle this scenario (maybe some hook like EVENT_BEFORE_USER_REGISTER in UserService which can alter the custom field validation and saving)?

Thank you in advance!

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions