summary refs log tree commit diff
path: root/src/connections/EpicGames
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-08-06 23:15:35 -0400
committerPuyodead1 <puyodead@proton.me>2023-08-06 23:15:35 -0400
commitfe4acbfee58e840412ed5d496fb565843d4a8cdd (patch)
tree3397988bd5ff2c812a0fbf688c1d375ad02df7d8 /src/connections/EpicGames
parentFix connection class imports (diff)
downloadserver-fe4acbfee58e840412ed5d496fb565843d4a8cdd.tar.xz
Fix linter warnings in connections
Diffstat (limited to 'src/connections/EpicGames')
-rw-r--r--src/connections/EpicGames/index.ts23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/connections/EpicGames/index.ts b/src/connections/EpicGames/index.ts
index 8521a6f3..e5b2d336 100644
--- a/src/connections/EpicGames/index.ts
+++ b/src/connections/EpicGames/index.ts
@@ -19,10 +19,10 @@
 import {
 	ConnectedAccount,
 	ConnectedAccountCommonOAuthTokenResponse,
+	Connection,
 	ConnectionCallbackSchema,
 	ConnectionLoader,
 	DiscordApiErrors,
-	Connection,
 } from "@spacebar/util";
 import wretch from "wretch";
 import { EpicGamesSettings } from "./EpicGamesSettings";
@@ -53,17 +53,21 @@ export default class EpicGamesConnection extends Connection {
 	settings: EpicGamesSettings = new EpicGamesSettings();
 
 	init(): void {
-		this.settings = ConnectionLoader.getConnectionConfig(
-			this.id,
-			this.settings,
-		) as EpicGamesSettings;
+		const settings =
+			ConnectionLoader.getConnectionConfig<EpicGamesSettings>(
+				this.id,
+				this.settings,
+			);
+
+		if (settings.enabled && (!settings.clientId || !settings.clientSecret))
+			throw new Error(`Invalid settings for connection ${this.id}`);
 	}
 
 	getAuthorizationUrl(userId: string): string {
 		const state = this.createState(userId);
 		const url = new URL(this.authorizeUrl);
 
-		url.searchParams.append("client_id", this.settings.clientId!);
+		url.searchParams.append("client_id", this.settings.clientId as string);
 		url.searchParams.append("redirect_uri", this.getRedirectUri());
 		url.searchParams.append("response_type", "code");
 		url.searchParams.append("scope", this.scopes.join(" "));
@@ -127,8 +131,11 @@ export default class EpicGamesConnection extends Connection {
 	async handleCallback(
 		params: ConnectionCallbackSchema,
 	): Promise<ConnectedAccount | null> {
-		const userId = this.getUserId(params.state);
-		const tokenData = await this.exchangeCode(params.state, params.code!);
+		const { state, code } = params;
+		if (!code) throw new Error("No code provided");
+
+		const userId = this.getUserId(state);
+		const tokenData = await this.exchangeCode(state, code);
 		const userInfo = await this.getUser(tokenData.access_token);
 
 		const exists = await this.hasConnection(userId, userInfo[0].accountId);