New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a custom User model with SimpleJWT #492
Comments
Try logging into the admin panel and lemme know if that works. I'm guessing you may not have set AUTH_USER_MODEL in settings |
I have set |
PS I login to the admin panel using a superuser created with |
Correct, it should now appear under your project's app which houses the custom user model. This is the proper functionality, and now SImpleJWT should work. |
but it doesn't 😅 I don't know what I'm doing wrong |
haha sorry! Yes please check if is_active=True because we do have a(n overridable) check in place for that. The admin has nothing to do with this package; it was just a test to see if settings.AUTH_USER_MODEL was actually done correctly. Do you mind setting up a reproducible repo? That would help! |
Hey, I created a repo with the files required to reproduce the issue! |
have you tried with an user created from the admin panel? please read the readme in the repo |
@obvionaoe ah my apologies. The problem is in your custom manager, you're not setting the password correctly: >>> from app.models import CustomUser
>>> CustomUser.objects.all()
<QuerySet [<CustomUser: asdf@asdf.com>, <CustomUser: asdf1@asdf.com>]>
>>> CustomUser.objects.all()[1].password
'asdf' The password should look like this: |
This is probably what you're looking for: https://stackoverflow.com/a/69594199 This tutorial can prob help as well: https://testdriven.io/blog/django-custom-user-model/#admin |
Closing. Reasoning: devs when using a custom user model need to ensure that when they are registering their models, they continue to use the UserAdmin: from django.contrib.auth.admin import UserAdmin
from django.contrib import admin
from app.models import CustomUser
# Inherit from UserAdmin and do more stuff
# Tutorial: https://testdriven.io/blog/django-custom-user-model/#admin
admin.site.register(CustomUser, UserAdmin) |
I ran into this also, so I wanted to document what was going wrong. Basically what is happening is that the error message is incorrect, and has nothing to do with custom user models. The actual root cause is circular imports, which just so happens to cause Django to fail on fetching the custom user model. In my specific case, I was using a custom serializer to add some information into the token claims, as shown here: https://django-rest-framework-simplejwt.readthedocs.io/en/latest/customizing_token_claims.html However in the same file I was also importing some other stuff from So when this line is executed: It resulting in a circular import. But instead of just giving a circular import error, it was complaining about the user model not being able to be found. Anyway sorry this doesn't come with a neat reproduction, but hopefully this hint at least helps someone else! (The solution btw was just to define |
Hi, I'm trying to use a custom User model/extension of the default Django auth.User model in my application.
I created the User and Manager like so:
but when I create users of this model and try to login into my app with them instead of getting a JWT token like before I get a message stating that there are no active users with those credentials...
How can I use SimpleJWT with a custom User model?
Thanks
The text was updated successfully, but these errors were encountered: