Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom User subclasses (#171)
## Description This PR changes the behavior of the `DescopeUser` model somewhat. Previously the `DescopeUser` model subclassed directly from Django's built-in `User` model, and was configured as a proxy model. This works fine if you only intend to use the Django built-in model, however this does not work if a user wants to define a custom model via the `AUTH_USER_MODEL` setting. This PR makes use of the `get_user_model` function from Django, and subclasses from that, which means that if a user specifies a custom model from their application in the `AUTH_USER_MODEL` setting, then the `DescopeUser` model will subclass from that. ## The two important things to note `DescopeUser` is no longer a proxy model, this functionally I don't think changes much, but does mean it creates it's own DB table, wether it adds any new fields or not. This has been changed because in Django, you can not create a proxy model off of another model which is not a base model. So for example, the proxy model would work with Django's built-in user as that is a base model, but it would not work on a custom user model that subclasses from Django's built-in. This does mean that the descope migrations can not be pre-shipped, and must be generated during the user application's run of `makemigrations`, because the DescopeUser migration will be dependent on the application's User model(and this may be Django's built-in, but in this scenario django-descope can't know that until the user creates their migrations). --------- Co-authored-by: Omer Cohen <[email protected]>
- Loading branch information