nrbnlulu / strawberry-django-auth

Authentication system for django using strawberry
https://nrbnlulu.github.io/strawberry-django-auth/
MIT License
68 stars 30 forks source link

register fails on channles requests. #137

Closed nrbnlulu closed 7 months ago

nrbnlulu commented 2 years ago

stacktrace:

GraphQL request:2:3
1 | mutation {
2 |   register(
  |   ^
3 |     input: {email: "princebrenda@example.org", username: "stevenbrown", password1: "xW1S9aTlH@", password2: "xW1S9aTlH@"}
Traceback (most recent call last):
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/graphql/execution/execute.py", line 528, in await_result
    return_type, field_nodes, info, path, await result
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler
    return func(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/core/field_.py", line 27, in _resolve
    return super().get_result(source, info, args, kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry_django/fields/field.py", line 112, in get_result
    return super().get_result(source, info, args, kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/field.py", line 167, in get_result
    return self.base_resolver(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/types/fields/resolver.py", line 187, in __call__
    return self.wrapped_func(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/core/mixins.py", line 36, in field
    return cls.resolve_mutation(info, input)  # type: ignore
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/user/resolvers.py", line 138, in resolve_mutation
    user.status.send_activation_email(info)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/models.py", line 77, in send_activation_email
    email_context = self.get_email_context(
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/models.py", line 62, in get_email_context
    site = get_current_site(request)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/django/contrib/sites/shortcuts.py", line 18, in get_current_site
    return RequestSite(request)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/django/contrib/sites/requests.py", line 11, in __init__
    self.domain = self.name = request.get_host()
AttributeError: 'GraphQLHTTPConsumer' object has no attribute 'get_host'
Stack (most recent call last):
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/channels/handlers/http_handler.py", line 163, in execute
    result = await self.schema.execute(
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/schema/schema.py", line 216, in execute
    self.process_errors(result.errors, execution_context=execution_context)

method to fix: https://github.com/nrbnlulu/strawberry-django-auth/blob/7c97c5024c1dc1f6dacd3fcffca0f0046325bc1c/gqlauth/models.py#L59

nrbnlulu commented 7 months ago

@shmoon-kr

I tried to fix it: request = info.context['request'] if isinstance(info.context, dict) else info.context.request but it still raises an error

The error is in get_current_site() I think the solution is to implement this function ourselves.