diff --git a/frontend/src/scripts/controllers/account-controller.js b/frontend/src/scripts/controllers/account-controller.js index 2519a4f7b..f9014ab9d 100644 --- a/frontend/src/scripts/controllers/account-controller.js +++ b/frontend/src/scripts/controllers/account-controller.js @@ -251,7 +251,7 @@ async function loadUser(user) { $(".pageAccount .group.createdDate").text(text); if (VerificationController.data !== null) { - VerificationController.verify(user); + VerificationController.verify(user.uid); } } diff --git a/frontend/src/scripts/controllers/verification-controller.js b/frontend/src/scripts/controllers/verification-controller.ts similarity index 66% rename from frontend/src/scripts/controllers/verification-controller.js rename to frontend/src/scripts/controllers/verification-controller.ts index 353b3589a..ecbf02f78 100644 --- a/frontend/src/scripts/controllers/verification-controller.js +++ b/frontend/src/scripts/controllers/verification-controller.ts @@ -3,22 +3,32 @@ import * as Settings from "../pages/settings"; import * as DB from "../db"; import axiosInstance from "../axios-instance"; import * as Loader from "../elements/loader"; +import { AxiosError } from "axios"; -export let data = null; -export function set(val) { +type Data = { + accessToken: string; + tokenType: string; + uid?: string; +}; + +export let data: Data | null = null; + +export function set(val: Data): void { data = val; } -export async function verify(user) { +export async function verify(uid: string): Promise { + if (data === null) return; Notifications.add("Linking Discord account", 0, 3); Loader.show(); - data.uid = user.uid; + data.uid = uid; let response; try { response = await axiosInstance.post("/user/discord/link", { data: data }); - } catch (e) { + } catch (error) { Loader.hide(); - let msg = e?.response?.data?.message ?? e.message; + const e = error as AxiosError; + const msg = e?.response?.data?.message ?? e.message; Notifications.add("Failed to link Discord: " + msg, -1); return; } diff --git a/frontend/src/scripts/ready.ts b/frontend/src/scripts/ready.ts index 2851e925a..4f85fa9e0 100644 --- a/frontend/src/scripts/ready.ts +++ b/frontend/src/scripts/ready.ts @@ -50,8 +50,8 @@ $(document).ready(() => { if (window.location.pathname === "/verify") { const fragment = new URLSearchParams(window.location.hash.slice(1)); if (fragment.has("access_token")) { - const accessToken = fragment.get("access_token"); - const tokenType = fragment.get("token_type"); + const accessToken = fragment.get("access_token") as string; + const tokenType = fragment.get("token_type") as string; VerificationController.set({ accessToken: accessToken, tokenType: tokenType,