From 3021920142a5dbcd359aef6c600c95921801491b Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 9 Sep 2024 20:00:38 -0400 Subject: [PATCH] only allow clients to run this function --- JS-SDK/package.json | 2 +- JS-SDK/src/lib/tether.ts | 10 +++++++--- JS-SDK/src/types/config.ts | 3 +-- JS-SDK/src/types/snowflake.ts | 3 +-- JS-SDK/src/types/socket.ts | 3 +-- JS-SDK/src/types/user.ts | 12 +++++------- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/JS-SDK/package.json b/JS-SDK/package.json index 3916a07..469ed2b 100644 --- a/JS-SDK/package.json +++ b/JS-SDK/package.json @@ -1,6 +1,6 @@ { "name": "usetether", - "version": "1.0.6", + "version": "1.0.7", "author": "Braydon (Rainnny) ", "description": "An API designed to provide real-time access to a user's Discord data.", "keywords": [ diff --git a/JS-SDK/src/lib/tether.ts b/JS-SDK/src/lib/tether.ts index cdb1410..362e937 100644 --- a/JS-SDK/src/lib/tether.ts +++ b/JS-SDK/src/lib/tether.ts @@ -1,7 +1,7 @@ -import TetherConfig from "@/types/config"; -import DiscordUser from "@/types/user"; import { useEffect, useState } from "react"; -import Snowflake from "@/types/snowflake"; +import { Snowflake } from "@/types/snowflake"; +import { TetherConfig } from "@/types/config"; +import { DiscordUser } from "@/types/user"; export const useTetherWS = ( snowflake: Snowflake, @@ -14,6 +14,10 @@ export const useTetherWS = ( const url: string = `ws${secure && "s"}://${endpoint}/gateway`; useEffect(() => { + // Prevent from running on the server + if (typeof window === "undefined") { + return; + } let socket: WebSocket; // The current WebSocket connection /** diff --git a/JS-SDK/src/types/config.ts b/JS-SDK/src/types/config.ts index cc221e2..2dd23f7 100644 --- a/JS-SDK/src/types/config.ts +++ b/JS-SDK/src/types/config.ts @@ -1,4 +1,4 @@ -type TetherConfig = { +export type TetherConfig = { /** * The API endpoint to connect to. */ @@ -9,4 +9,3 @@ type TetherConfig = { */ secure?: boolean; }; -export default TetherConfig; diff --git a/JS-SDK/src/types/snowflake.ts b/JS-SDK/src/types/snowflake.ts index 11ad6d4..368b1ac 100644 --- a/JS-SDK/src/types/snowflake.ts +++ b/JS-SDK/src/types/snowflake.ts @@ -1,2 +1 @@ -type Snowflake = `${bigint}`; -export default Snowflake; +export type Snowflake = `${bigint}`; diff --git a/JS-SDK/src/types/socket.ts b/JS-SDK/src/types/socket.ts index 45560f3..1e49ad6 100644 --- a/JS-SDK/src/types/socket.ts +++ b/JS-SDK/src/types/socket.ts @@ -1,7 +1,6 @@ -type SocketPacket = { +export type SocketPacket = { /** * The OP code for this packet. */ op: number; }; -export default SocketPacket; diff --git a/JS-SDK/src/types/user.ts b/JS-SDK/src/types/user.ts index e54ac88..5d3c8cd 100644 --- a/JS-SDK/src/types/user.ts +++ b/JS-SDK/src/types/user.ts @@ -1,4 +1,4 @@ -type DiscordUser = { +export type DiscordUser = { /** * The unique snowflake of this user. */ @@ -69,7 +69,7 @@ type DiscordUser = { /** * A user's flags. */ -type UserFlags = { +export type UserFlags = { /** * The list of flags the user has. */ @@ -101,7 +101,7 @@ type UserFlags = { /** * A user's avatar. */ -type Avatar = { +export type Avatar = { /** * The id of the user's avatar. */ @@ -116,7 +116,7 @@ type Avatar = { /** * A user's banner. */ -type Banner = { +export type Banner = { /** * The id of the user's avatar. */ @@ -131,7 +131,7 @@ type Banner = { /** * A user's Spotify activity data. */ -type SpotifyActivity = { +export type SpotifyActivity = { /** * The currently playing song. */ @@ -167,5 +167,3 @@ type SpotifyActivity = { */ ends: number; }; - -export default DiscordUser;