Django-allauth stuck on signup and headless=True confusion
I'm trying to setup django-allauth app to be used for authentication by a front end react app and a mobile app. There are some inconsistencies which most likely are just down to me not figuring out something. But ton's of googling and AI ain't helping.
I've done the setup (several times) as per the tutorial and using postman and I'm able to call /auth/login
successfully for a user that had been created using createsuperuser
My confusion/uncertainty starts when I try signup a new user via /auth/signup
. It is "sort off" successful. I say sort of because the user does get created in the DB but I do not receive the email asking the user to Confirm Their Email
.
When I however try register the same email/user again, I now get an email saying [example.com] Account Already Exists
. So I do know email delivery (using mailhog) is working.
Here are my allaluth settings:
HEADLESS_ONLY = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_LOGIN_METHODS = {
"email",
}
ACCOUNT_SIGNUP_FIELDS = ["email*", "password1*",]
ACCOUNT_SIGNUP_FORM_CLASS = "authy.forms.CustomSignupForm"
ACCOUNT_EMAIL_VERIFICATION = "mandatory" # Ensures users must verify their email
ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None # or a url
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = None # or a url
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
I have the signup form as below:
class CustomSignupForm(forms.Form):
email = forms.CharField(required=True, label="Email Address")
mobile_number = forms.CharField(max_length=20, required=True, label="Mobile Number")
first_name = forms.CharField(max_length=50, required=True, label="First Name")
last_name = forms.CharField(max_length=50, required=True, label="Last Name")
def signup(self, request, user):
"""This method is automatically called by AllAuth after signup.
"""
user.mobile_number = self.cleaned_data["mobile_number"]
user.save()
HEADLESS = TRUE
The scenario described above is when I have headless = False
.
Given that I'm building a Django API to be used by a react front end, I assumed that I need to set headless = True
. If I do that however, I find that the first time I create user through auth/signup
, I get a 401 and the details below. I still DON'T get an email.
{
"status": 401,
"data": {
"flows": [
{
"id": "login"
},
{
"id": "signup"
}
]
},
"meta": {
"is_authenticated": false,
"session_token": "m18gi8fso3hj75l7ogrhv47bn45jqcap"
}
}
If I attempt to register the same details again, I get an error stating Reverse for 'account_signup' not found. 'account_signup' is not a valid view function or pattern name.
Googling that error shows it's because I don't have path("accounts/", include("allauth.urls")),
in the urls.py. But my understanding is that with headless, this URLs are not expected?
I also notice that when the user signs up, all fields in the form are automatically saved apart from mobile_number
. This is why I have to explicitly assign it to the user instance and save (update). What I'm I missing there?
To summarize my misunderstanding:
- User gets created but email not being sent. Yet when I send that payload again, I am able to receive an email? Is there some setting that I haven't turned on?
- Why do I get the error about
account_signup not found
yet when I setheadless = True
those APIs don't even show up when I dopython manage.py show_url
(using djang-extensions)? Some thread/issue/reddit/ai seemed to state that when usingheadless = True
we cannot take advantage of the automatic emailing and other such features. That we have to build that on our own? I doubt that but hence the reason for this question here. - Why is it that
mobile_number
isn't auto saved like all other fields? Should I even be using a custom form whenheadless = True
or I have to build all my APIs using DRF Views and Serialilzers?. Note that mobile_number is a field in an existing custom user model