Skip to content

auth on a per topic basis #397

Answered by enisdenjo
fierysolid asked this question in Q&A
Discussion options

You must be logged in to vote

You can indeed use the onSubscribe server hook. To deny a subscription, you can just return an error from it and handle the error however you please on the client.

async function onSubscribe(ctx, msg) {
  const can = await checkCanSubscribe(ctx, msg);
  if (!can) {
    // user doesnt have access, return error for this exact subscription
    return [new GraphQLError('Forbidden')];
  }

  // user has access, return nothing to proceed with the regular flow
}

Replies: 1 comment 2 replies

Comment options

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

@enisdenjo
Comment options

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