Commit a931ece
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 <omer@descope.com>1 parent b843bdc commit a931ece
2 files changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
0 commit comments