Skip to content

Commit

Permalink
docs: use close code forbidden [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Sep 17, 2021
1 parent 43da515 commit 1aee1e8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ const client = createClient({

import ws from 'ws'; // yarn add ws
import { useServer } from 'graphql-ws/lib/use/ws';
import { CloseCode } from 'graphql-ws';
import { schema } from './my-graphql-schema';
import { isTokenValid } from './my-auth';

Expand All @@ -1489,12 +1490,12 @@ useServer(
onSubscribe: async (ctx) => {
// or maybe on every subscribe
if (!(await isTokenValid(ctx.connectionParams?.token)))
return ctx.extra.socket.close(4403, 'Forbidden');
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(4403, 'Forbidden');
return ctx.extra.socket.close(CloseCode.Forbidden, 'Forbidden');
},
},
wsServer,
Expand Down Expand Up @@ -1548,7 +1549,7 @@ const client = createClient({
// will set the token refresh flag to true
tokenExpiryTimeout = setTimeout(() => {
if (socket.readyState === WebSocket.OPEN)
socket.close(CloseCode.Unauthorized, 'Unauthorized');
socket.close(CloseCode.Forbidden, 'Forbidden');
}, getCurrentTokenExpiresIn());
},
closed: (event) => {
Expand Down

0 comments on commit 1aee1e8

Please sign in to comment.