From 45d1649474a7e95b0b1f6530e2f3d3cb3d734db8 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Mon, 2 May 2022 15:21:52 +0200 Subject: [PATCH] docs: recommend auth in onConnect [skip ci] --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index efcc7daa..06ec2415 100644 --- a/README.md +++ b/README.md @@ -1018,17 +1018,13 @@ function handleAuth(request: http.IncomingMessage) { const gqlServer = makeServer({ schema, onConnect: async (ctx) => { - // do your auth on every connect + // do your auth on every connect (recommended) await handleAuth(ctx.extra.request); }, onSubscribe: async (ctx) => { // or maybe on every subscribe await handleAuth(ctx.extra.request); }, - onNext: async (ctx) => { - // haha why not on every result emission? - await handleAuth(ctx.extra.request); - }, }); // create websocket server @@ -1713,7 +1709,7 @@ useServer( { schema, onConnect: async (ctx) => { - // do your auth check on every connect + // do your auth check on every connect (recommended) if (!(await isTokenValid(ctx.connectionParams?.token))) // returning false from the onConnect callback will close with `4403: Forbidden`; // therefore, being synonymous to ctx.extra.socket.close(4403, 'Forbidden'); @@ -1724,11 +1720,6 @@ useServer( if (!(await isTokenValid(ctx.connectionParams?.token))) return ctx.extra.socket.close(CloseCode.Forbidden, 'Forbidden'); }, - onNext: async (ctx) => { - // why not on every result emission? lol - if (!(await isTokenValid(ctx.connectionParams?.token))) - return ctx.extra.socket.close(CloseCode.Forbidden, 'Forbidden'); - }, }, wsServer, );