converted verification controller to ts

This commit is contained in:
Miodec 2022-02-19 22:06:48 +01:00
parent a2ecc054d4
commit 370a873e60
3 changed files with 19 additions and 9 deletions

View file

@ -251,7 +251,7 @@ async function loadUser(user) {
$(".pageAccount .group.createdDate").text(text);
if (VerificationController.data !== null) {
VerificationController.verify(user);
VerificationController.verify(user.uid);
}
}

View file

@ -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<void> {
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;
}

View file

@ -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,