Skip to content
Discussion options

You must be logged in to vote

Hi @samvv! Thanks for the love! 😊

Maybe @bellini666 has a better answer, but I usually tend to get the user in the resolver and do filtering based on that (and combined with permission to force auth), something like this:

class IsAuthenticated(BasePermission):
    message = "User is not authenticated"
    
    def has_permission(self, source, info, **kwargs):
        return info.context.request.user.is_authenticated

@strawberry.type
class Query:
    @strawberry.field(permission_classes=[IsAuthenticated])
    def items(self, info: strawberry.Info) -> list[Item]:
        user = info.context.request.user
        
        if user.is_superuser:
            # Superuser can see everything

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@bellini666
Comment options

@samvv
Comment options

Answer selected by samvv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants