2024-11-06 15:27:33 +03:00

35 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { browser } from "$app/environment";
import { getAuthInfo, makeAuthHeaderForAxios } from "$lib/auth/Auth";
import { makePost } from "$lib/tools/requests/requests";
import { sayError } from "$lib/tools/toaster/Toaster";
import { redirect } from "$lib/tools/url/URLTools";
export async function load({ params }) {
if(!browser) return;
const { userToken } = params;
let userResult = await makePost(
"getUser",
{
token: userToken,
},
makeAuthHeaderForAxios(getAuthInfo()?.a)
);
if (userResult.status === 401) {
sayError("Данные авторизации устарели");
// window.location.href = "/";
redirect("/admin/");
return {};
}
if (userResult.error) {
sayError("Не удалось настроить пользователя");
return {};
}
userResult["can_trade"] = userResult["can_trade"] === "t" ? true:false;
userResult["can_trade_global"] = userResult["can_trade_global"] === "t" ? true:false;
userResult["balance"] = Number(userResult["balance"]);
userResult["bid"] = Number(userResult["bid"]);
return {
token: userToken,
userData: userResult.data
};
}