PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.
https://django-graphql-auth.readthedocs.io/en/latest/
MIT License
333 stars 105 forks source link

Custom User model = Unknown field(s) (username) specified for User #86

Open rad-eric opened 4 years ago

rad-eric commented 4 years ago

I've read up on the following

https://github.com/PedroBern/django-graphql-auth/issues/54 https://github.com/PedroBern/django-graphql-auth/issues/9

but i am still getting Unknown field(s) (username) specified for User - i do have USERNAME_FIELD = "email" on my custom User model:

class User(AbstractBaseUser):
    objects = UserManager()
    email = models.EmailField(
        verbose_name="email address",
        max_length=255,
        unique=True,
    )
    firstname = models.CharField(max_length=200, blank=False, null=False)
    lastname = models.CharField(max_length=200, blank=False, null=False)
    active = models.BooleanField(default=True)
    staff = models.BooleanField(default=False)  # a admin user; non super-user
    admin = models.BooleanField(default=False)  # a superuser

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

and settings

AUTH_USER_MODEL = 'vendors.User'
GRAPHENE = {
    'MIDDLEWARE': [
        'graphql_jwt.middleware.JSONWebTokenMiddleware',
    ],
    'SCHEMA': 'api.schema.schema'  # Where your Graphene schema lives
}
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

AUTHENTICATION_BACKENDS = [
    "graphql_auth.backends.GraphQLAuthBackend",
    'django.contrib.auth.backends.ModelBackend',
]
GRAPHQL_AUTH = {
    'LOGIN_ALLOWED_FIELDS': ['email'],
    # ...
}
# focus on change password for now
GRAPHQL_JWT = {
    "JWT_ALLOW_ANY_CLASSES": [
        "graphql_auth.mutations.PasswordChange",
    ],
}

but i still get the following:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/api/v2/graphql

Django Version: 3.1.3
Python Version: 3.9.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.gis',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'django_filters',
 'graphene_django',
 'django_cron',
 'polymorphic',
 'vendors',
 'graphql_auth']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphql_jwt/decorators.py", line 122, in wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/django/views/generic/base.py", line 63, in view
    self = cls(**initkwargs)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphene_django/views.py", line 100, in __init__
    schema = graphene_settings.SCHEMA
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphene_django/settings.py", line 126, in __getattr__
    val = perform_import(val, attr)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphene_django/settings.py", line 65, in perform_import
    return import_from_string(val, setting_name)
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphene_django/settings.py", line 79, in import_from_string
    module = importlib.import_module(module_path)
  File "/Users/eric/.pyenv/versions/3.9.0/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
    <source code not available>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
    <source code not available>
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
    <source code not available>
  File "/Users/eric/Documents/RAD/fleet-django/fleetmanagement/api/schema.py", line 4, in <module>
    from api.mutations.mutations import Mutation as Mutations
  File "/Users/eric/Documents/RAD/fleet-django/fleetmanagement/api/mutations/mutations.py", line 15, in <module>
    from graphql_auth import mutations
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphql_auth/mutations.py", line 5, in <module>
    from .mixins import (
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphql_auth/mixins.py", line 15, in <module>
    from .forms import RegisterForm, EmailForm, UpdateAccountForm, PasswordLessRegisterForm
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/graphql_auth/forms.py", line 9, in <module>
    class RegisterForm(UserCreationForm):
  File "/Users/eric/.virtualenvs/fleetmanagementenv/lib/python3.9/site-packages/django/forms/models.py", line 268, in __new__
    raise FieldError(message)

Exception Type: FieldError at /api/v2/graphql
Exception Value: Unknown field(s) (username) specified for User

I've tried to follow the install to a T

vadolasi commented 4 years ago

See #72, Maybe it will help.