reactjs socket.io-client ERR_CERT_AUTHORITY_INVALID

Viewed 196

I'm trying to connect to tls websocket but i get websocket.js:120 WebSocket connection to ' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

here's the code I'm trying to use

import SocketIOClient from "socket.io-client";
import * as types from "../constants/sockets";

const URL = "SERVER";

export function missingSocketConnection() {
  return {
    type: types.SOCKETS_CONNECTION_MISSING,
    payload: new Error("Missing connection!"),
  };
}

let socket = null;

export function socketsConnect() {
  return (dispatch, getState) => {
    const state = getState();
    const { isFetching } = state.services;
    const { token } = state.auth;

    if (isFetching.sockets) {
      return Promise.resolve();
    }

    dispatch({
      type: types.SOCKETS_CONNECTION_REQUEST,
    });

    socket = SocketIOClient(URL, {
      reconnection: false,
      path: "/",
      transports: ["websocket"],
      query: { token },
      rejectUnauthorized: false,
      secure: false,
      upgrade: false,
    });

    socket.on("connect", () => {
      dispatch({
        type: types.SOCKETS_CONNECTION_SUCCESS,
      });
    });

    socket.on("error", (error) => {
      dispatch({
        type: types.SOCKETS_CONNECTION_FAILURE,
        payload: new Error(`Connection: ${error}`),
      });
    });

    socket.on("connect_error", () => {
      dispatch({
        type: types.SOCKETS_CONNECTION_FAILURE,
        payload: new Error("We have lost a connection :("),
      });
    });

    return Promise.resolve();
  };
}

i tried providing the cert by import crt from "path/to/crt" but didn't work either also tried tweaking the options to secure: true the same server allowed connection without using the certificate using C# and Websocket-Sharp

0 Answers
Related