Authentication
All websocket API calls require authentication prior to invoking functions.
Last updated
Was this helpful?
Was this helpful?
npm i @microsoft/signalr// Import the signalr library for backend connection
const signalR = require("@microsoft/signalr");
// Establist the connection object
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://api.sonorancad.com/apiWsHub", {
transport: signalR.HttpTransportType.WebSockets,
skipNegotiation: true,
})
.withAutomaticReconnect()
.build();
// Start the WSS connection
await connection.start();
// Replace community ID and API key
const auth = await connection.invoke("authenticatev2", "yourCommunityId", "yourApiKey", 1);
if (!auth?.success) {
throw new Error(`Authentication failed: ${auth?.error || "unknown error"}`);
}