Django - Allauth doesnt use the custom signup form
I work with Django-Allauth and React as a FE. I added a parameter called name for for the Custom User I created, I've overridden the SignupForm in Forms.py to save it, and just like the documentation said I changed the settings.py to have
ACCOUNT_FORMS = {'signup': 'XXXX.forms.CustomSignupForm'}
But the form does not get initiated when signing up - i added prints that don't go through. A user is being created - but probably with the default form, and doesn't add the additional parameter I added. I checked and the frontend sends the payload properly.
I have this in forms.py
class CustomUserCreationForm(UserCreationForm):
name = forms.CharField(max_length=30, required=True, help_text='Enter your name.')
class Meta:
model = CustomUser
fields = ("email", "name")
class CustomSignupForm(SignupForm):
name = forms.CharField(max_length=40, required=True, help_text='Enter your name.')
def __init__(self, *args, **kwargs):
print("CustomSignupForm is being initialized")
super().__init__(*args, **kwargs)
def save(self, request):
print("im working")
user = super().save(request)
user.name = self.cleaned_data['name']
user.save()
return user
urls.py
urlpatterns = [
path("admin/", admin.site.urls),
path('', include('XXXX.urls')),
path('accounts/', include('allauth.urls')),
path("_allauth/", include("allauth.headless.urls")),
]
I also tried using an ACCOUNT_ADAPTER in settings, and this is how the adapter looks in adapters.py
class CustomAccountAdapter(DefaultAccountAdapter):
# def get_signup_form_class(self):
# return CustomSignupForm
But it didn't use the form.
Also tried to edit the CustomUserManager, but the form is a step before it if I'm not mistaken so it didn't help as well. I tried looking everywhere, and in the documentation, but couldn't find a solution or a hint. Thanks a lot!
An important thing to keep in mind is that there is no one-to-one
mapping of headed forms to headless input payloads. For example, while having to
enter your password twice makes sense in a headed environment, it is pointless
from an API point of view. As a result, the headed forms that can be overridden
by means of ACCOUNT_FORMS
play no role in the headless environment.
Instead of overriding the complete signup form via ACCOUNT_FORMS
, provide a
ACCOUNT_SIGNUP_FORM_CLASS
that derives from forms.Form
and only lists
the additional fields you need. These fields will automatically show up in the
headed signup form, and will automatically be validated when posting payloads to
the signup endpoint.