Extension IsAuthenticated
shows up in schema but does not actually trigger
#3953
-
Hi again, I'm almost through most of the interesting work but I'm stuck on one particular issue. I'm using I have this in from gqlauth.user.queries import UserQueries
import strawberry
from strawberry_django.permissions import IsAuthenticated
import strawberry_django
from core.models import Person as PersonModel
@strawberry_django.type(PersonModel)
class Person:
id: auto
email: auto
full_name: auto
# possibly more fields in the future
@strawberry.type
class Query(UserQueries):
@strawberry_django.field(
extensions=[IsAuthenticated()]
)
def persons(self, info: strawberry.Info) -> list[Person]:
...
# more fields here
# mutations and so on here
schema = JwtSchema(
query=Query,
mutation=Mutation,
extensions=[
DjangoOptimizerExtension,
],
) For some reason the following query does not give an 'authentication required' error, even though I quite clearly see it in the source code of query Test {
persons {
id
}
} {
"data": {
"persons": []
}
} Does anyone know what I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @samvv , This is because of how the "No Permission Handling" works when the return value can be You can pass Just noticed that |
Beta Was this translation helpful? Give feedback.
Hi @samvv ,
This is because of how the "No Permission Handling" works when the return value can be
null
or alist
: https://strawberry.rocks/docs/django/guide/permissions#no-permission-handlingYou can pass
fail_silently=False
toIsAuthenticated
(i.e.IsAuthenticated(fail_silently=False)
), and that should make you get the authentication error.Just noticed that
fail_silently
is not documented in the docs, I'm going to try to add it there soon