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

No USERNAME_FIELD #134

Closed portedison closed 2 years ago

portedison commented 2 years ago

If I try to register with just email and Password1/2 I get caught in graphql_jwt : token_auth username = kwargs.get(get_user_model().USERNAME_FIELD), where kwargs doesn't contain my username. On our custom user model we're just assigning a uuid to username. Do you have any recommendations as to how to work around this? Some people recommend USERNAME_FIELD = 'email'. The script continues, delivers the authentication email, then returns, generic GraphQLLocatedError.

GRAPHQL_AUTH = {
    'REGISTER_MUTATION_FIELDS': ["email", ],
}
def save(self, *args, **kwargs):
        if not getattr(self, self.USERNAME_FIELD, None):
            setattr(self, self.USERNAME_FIELD, uuid.uuid4().hex)
        super().save(*args, **kwargs)
File "/Users//.virtualenvs/.../lib/python3.8/site-packages/graphql_auth/mixins.py", line 123, in resolve_mutation
    payload = cls.login_on_register(
  File "/Users//.virtualenvs/.../lib/python3.8/site-packages/graphql_jwt/decorators.py", line 110, in wrapper
    result = f(cls, root, info, **kwargs)
  File "/Users//.virtualenvs/.../lib/python3.8/site-packages/graphql_jwt/decorators.py", line 90, in wrapper
    raise exceptions.JSONWebTokenError(
graphql.error.located_error.GraphQLLocatedError: Please, enter valid credentials
portedison commented 2 years ago

This is resolved. I followed the instructions here. https://www.fomfus.com/articles/how-to-use-email-as-username-for-django-authentication-removing-the-username/