Open miladjobs opened 4 years ago
Hi @miladjobs is it all the information that I need to replicate it? I will try to replicate and come back here, but this week I do not have time, maybe next week.
But first please print your packages here (use pip freeze
).
Thank you very much . requirements:
aniso8601==7.0.0
asgiref==3.2.7
backcall==0.1.0
certifi==2020.4.5.1
chardet==3.0.4
decorator==4.4.2
Django==3.0.4
django-cors-headers==3.2.1
django-filter==2.2.0
django-graphql-auth==0.3.6
django-graphql-jwt==0.3.0
graphene==2.1.8
graphene-django==2.9.0
graphql-core==2.3.1
graphql-relay==2.0.1
gunicorn==19.6.0
idna==2.9
ipython==7.13.0
ipython-genutils==0.2.0
jedi==0.16.0
parso==0.6.2
pexpect==4.8.0
pickleshare==0.7.5
promise==2.3
prompt-toolkit==3.0.5
psycopg2==2.8.4
ptyprocess==0.6.0
Pygments==2.6.1
PyJWT==1.7.1
python-dateutil==2.8.1
pytz==2019.3
requests==2.23.0
Rx==1.6.1
singledispatch==3.4.0.3
six==1.14.0
sqlparse==0.3.1
traitlets==4.3.3
urllib3==1.25.8
wcwidth==0.1.9
some other settings :
AUTH_USER_MODEL = 'users.MyUser'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
Student Node :
class StudentNode(DjangoObjectType):
class Meta:
model = Student
filter_fields = {
'user__first_name': ['exact', 'icontains', 'istartswith'],
'user__last_name': ['exact', 'icontains', 'istartswith'],
'std_id': ['exact', 'icontains', 'istartswith'],
'room__number': ['exact'],
'room__floor__number': ['exact'],
'room__floor__block__number': ['exact'],
'room__floor__block__dormitory__name': ['exact', 'icontains', 'istartswith'],
'grade': ['exact'],
}
interfaces = (graphene.relay.Node,)
Student Model:
class Student(models.Model):
user = models.OneToOneField(MyUser, on_delete=models.CASCADE, primary_key=True, related_name='student')
std_id = models.CharField(max_length=8, unique=True)
Note : Student register in another mutation api and connect to user
i was thinking it is because you are using 'JWT_EXPIRATION_DELTA': timedelta(minutes=60),
Did you made any progress on it?
If you need help to setup JWT on the client, here is a good resource.
@sirb0rab0g1 I got fresh token with tokenauth and few sconds later with postman i call query API with token on header and get anonymous user. But after my own query i called "me" query and get back true authenticated user. If expiration have problem , "me" query must also have problem
I have found that after return of "mutate_and_get_playload" or "resolve query" user being authenticated but must be called before call of those methods. Do you have any idea why this is so? @PedroBern
@miladjobs didn't understand what you mean, could you give an example?
I have the same problem with info.context.user
I think problem with this :/
My query
user = graphene.Field(UserType, token=graphene.String(required=True))
users = graphene.List(UserType)
@login_required
def resolve_user(self, info, **kwargs):
print(info.context.user.id, 'my user schema id')
return info.context.user
@login_required
def resolve_users(self, info):
return get_user_model().objects.all()
this views I have good id on console
but when I go to other schema and model
def resolve_posts_author(self, info):
print(info.context.user.id, 'my user author id')
return Post.objects.order_by('-updated_at').filter(author_id=info.context.user.id)
and print mi nothing or id sessions log admin panel
@miladjobs did you have any luck with not getting anonymous user ?
Hello I have problem with authenticate. At first i called "me" query i got null user. At second i wrote one authentication backend and me query fixed but when i write one query and inside it use
info.context.user
i get Anonymous user. when i debug it the code never go to backend authentication but in me query gone.Somethings that i have done but not fixed:
With these codes me query work well but own query not
MyCustom User:
MyCustom UserManager :
My Custom Authentication Backend :
My Own Qury :
My settings: