summary refs log tree commit diff
path: root/src/connections/Reddit/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/connections/Reddit/index.ts')
-rw-r--r--src/connections/Reddit/index.ts20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/connections/Reddit/index.ts b/src/connections/Reddit/index.ts

index c529cfa3..182cd5a5 100644 --- a/src/connections/Reddit/index.ts +++ b/src/connections/Reddit/index.ts
@@ -1,6 +1,7 @@ import { Config, ConnectedAccount, + ConnectedAccountCommonOAuthTokenResponse, ConnectionCallbackSchema, ConnectionLoader, DiscordApiErrors, @@ -9,14 +10,6 @@ import fetch from "node-fetch"; import Connection from "../../util/connections/Connection"; import { RedditSettings } from "./RedditSettings"; -interface OAuthTokenResponse { - access_token: string; - token_type: string; - scope: string; - refresh_token?: string; - expires_in?: number; -} - export interface UserResponse { verified: boolean; coins: number; @@ -72,7 +65,10 @@ export default class RedditConnection extends Connection { return this.tokenUrl; } - async exchangeCode(state: string, code: string): Promise<string> { + async exchangeCode( + state: string, + code: string, + ): Promise<ConnectedAccountCommonOAuthTokenResponse> { this.validateState(state); const url = this.getTokenUrl(); @@ -95,7 +91,6 @@ export default class RedditConnection extends Connection { }), }) .then((res) => res.json()) - .then((res: OAuthTokenResponse) => res.access_token) .catch((e) => { console.error( `Error exchanging token for ${this.id} connection: ${e}`, @@ -118,8 +113,8 @@ export default class RedditConnection extends Connection { params: ConnectionCallbackSchema, ): Promise<ConnectedAccount | null> { const userId = this.getUserId(params.state); - const token = await this.exchangeCode(params.state, params.code!); - const userInfo = await this.getUser(token); + const tokenData = await this.exchangeCode(params.state, params.code!); + const userInfo = await this.getUser(tokenData.access_token); const exists = await this.hasConnection(userId, userInfo.id.toString()); @@ -128,7 +123,6 @@ export default class RedditConnection extends Connection { // TODO: connection metadata return await this.createConnection({ - access_token: token, user_id: userId, external_id: userInfo.id.toString(), friend_sync: params.friend_sync,