How to use the @nestjs/websockets.WsException function in @nestjs/websockets

To help you get started, weโ€™ve selected a few @nestjs/websockets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github backstopmedia / nest-book-example / src / gateways / user / user.gateway.ts View on Github external
show(client, data): WsResponse {
        if (!data.userId) throw new WsException('Missing entry id.');
        if (client.handshake.user.id !== data.userId) throw new WsException('Unable to find the user.');

        const user = client.handshake.user;
        return { event: 'showUser', data: user };
    }
}
github backstopmedia / nest-book-example / src / shared / middlewares / ws-authentication.gateway.middleware.ts View on Github external
return (req, next) => {
            const matches = req.url.match(/token=([^&].*)/);
            req['token'] = matches && matches[1];

            if (!req.token) {
                throw new WsException('Missing token.');
            }

            return jwt.verify(req.token, 'secret', async (err, payload) => {
                if (err) throw new WsException(err);

                const user = await this.userService.findOne({ where: { email: payload.email }});
                req.user = user;
                return next(true);
            });
        }
    }
github backstopmedia / nest-book-example / src / gateways / comment / comment.gateway.ts View on Github external
async show(client, data): Promise> {
        if (!data.entryId) throw new WsException('Missing entry id.');
        if (!data.commentId) throw new WsException('Missing comment id.');

        const comment = await this.commentService.findOne({
            where: {
                id: data.commentId,
                entryId: data.entryId
            }
        });

        return { event: 'showComment', data: comment };
    }
}
github oznu / homebridge-config-ui-x / src / core / auth / auth.service.ts View on Github external
async verifyWsConnection(client) {
    try {
      return jwt.verify(client.handshake.query.token, this.configService.secrets.secretKey);
    } catch (e) {
      client.disconnect();
      throw new WsException('Unauthorized');
    }
  }
  /**
github backstopmedia / nest-book-example / src / shared / middlewares / ws-authentication.gateway.middleware.ts View on Github external
return jwt.verify(req.token, 'secret', async (err, payload) => {
                if (err) throw new WsException(err);

                const user = await this.userService.findOne({ where: { email: payload.email }});
                req.user = user;
                return next(true);
            });
        }
github xmlking / ngx-starter-kit / apps / api / src / app / auth / passport / ws-jwt.strategy.ts View on Github external
handleSigningKeyError: (err, cb) => {
        if (err instanceof SigningKeyNotFoundError) {
          return cb(new WsException('This is bad: SigningKeyNotFoundError'));
        }
        return cb(err);
      },
github backstopmedia / nest-book-example / src / gateways / comment / comment.gateway.ts View on Github external
async index(client, data): Promise> {
        if (!data.entryId) throw new WsException('Missing entry id.');

        const comments = await this.commentService.findAll({
            where: {entryId: data.entryId}
        });

        return { event: 'indexComment', data: comments };
    }
github oznu / homebridge-config-ui-x / src / modules / status / status.gateway.ts View on Github external
async getOutOfDatePlugins(client, payload) {
    try {
      return await this.pluginsService.getOutOfDatePlugins();
    } catch (e) {
      return new WsException(e.message);
    }
  }
}
github backstopmedia / nest-book-example / src / shared / middlewares / authentication.gateway.middleware.ts View on Github external
return (socket, next) => {
            if (!socket.handshake.query.auth_token) {
                throw new WsException('Missing token.');
            }

            return jwt.verify(
                socket.handshake.query.auth_token,
                'secret',
                async (err, payload) => {
                    if (err) throw new WsException(err);

                    const user = await this.userService.findOne({
                        where: { email: payload.email }
                    });
                    socket.handshake.user = user;
                    return next();
                }
            );
        };
github oznu / homebridge-config-ui-x / src / modules / status / status.gateway.ts View on Github external
async homebridgeVersionCheck(client, payload) {
    try {
      return await this.pluginsService.getHomebridgePackage();
    } catch (e) {
      return new WsException(e.message);
    }
  }

@nestjs/websockets

Nest - modern, fast, powerful node.js web framework (@websockets)

MIT
Latest version published 7 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages