Ajax User registration sometimes forbidden 403 error I am experiencing a very weird issue. I have a simple user registration form:

&lt;form method="post" action="" accept-charset="UTF-8" id="addTeacherForm"&gt;
    {{ csrfInput() }}

    &lt;input type="hidden" name="action" value="users/save-user" /&gt;
    &lt;input type="hidden" name="fields[schoolId][]" value="{{ currentUser.id }}" /&gt;
    &lt;input type="hidden" name="groups[]" value="3" /&gt;

    &lt;div class="form-group"&gt;
        &lt;label for="username"&gt;Username &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
        &lt;input id="username" type="text" class="form-control" name="username" required /&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
         &lt;label for="email"&gt;E-mailadres &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
        &lt;input id="email" type="text" class="form-control" name="email" required /&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        &lt;label for="password"&gt;Password &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
        &lt;input id="password" type="password" class="form-control" name="password" required /&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        &lt;button type="submit" class="btn btn-primary btn-submit float-right"&gt;
            Docent toevoegen
        &lt;/button&gt;
    &lt;/div&gt;
&lt;/form&gt;


I have an event listener for the form submit and I submit the form using ajax. This code works perfectly most of the time, but sometimes (like 20% of the time) I get a 403 forbidden error in the console. When I comment out the hidden groups[] input field I don't experience this issue at all. 

It is also worth noting that even though I get this error the user is created but doesn't get added to the group.

I'm starting to think this is a craft 3 issue. 

Can I somehow solve this?

Thanks!
Can I somehow solve this?


Yes by creating a custom Controller. Because the default UsersController does the following

// Don't validate required custom fields if it's public registration
if (!$thisIsPublicRegistration) {
    $user-&gt;setScenario(Element::SCENARIO_LIVE);
}


without SCENARIO_LIVE custom fields won't be stored