Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

login required? #7

Open
androane opened this issue Jun 27, 2018 · 1 comment
Open

login required? #7

androane opened this issue Jun 27, 2018 · 1 comment

Comments

@androane
Copy link

How would you handle a "login required" functionality with this approach?

@creimers
Copy link
Owner

I wrote a decorator like so:

from graphql import GraphQLError


def login_required(function):
    """
    use this decorator for mutations that require an
    authenticated user
    """

    def function_wrapper(*args, **kwargs):
        info = args[1]
        if info.context.user.is_authenticated:
            return function(*args, **kwargs)
        else:
            raise GraphQLError("unauthenticated")
    
    return function_wrapper

This I'm using to decorate the mutation's method:

@login_required
def mutate(self, info, this, that):
    pass

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants