Web: Common: the login function is moved to a separate file

This commit is contained in:
Artem Tarasov 2022-08-17 10:23:46 +03:00
parent 39d5419790
commit f21c7812ab
2 changed files with 28 additions and 2 deletions

View File

@ -2,8 +2,9 @@ import { LANGUAGE, AppServerConfig } from "../constants";
import sjcl from "sjcl";
import { isMobile } from "react-device-detect";
import TopLoaderService from "@docspace/components/top-loading-indicator";
import { Encoder } from "./encoder";
import FilesFilter from "../api/files/filter";
const { proxyURL } = AppServerConfig;
export const toUrlParams = (obj, skipNull) => {
let str = "";
@ -326,7 +327,6 @@ export function convertLanguage(key) {
return key;
}
import FilesFilter from "../api/files/filter";
export function getFolderOptions(folderId, filter) {
if (folderId && typeof folderId === "string") {
folderId = encodeURIComponent(folderId.replace(/\\\\/g, "\\"));

View File

@ -0,0 +1,26 @@
import api from "../api";
export async function login(user: string, hash: string, session = true) {
try {
const response = await api.user.login(user, hash, session);
if (!response || (!response.token && !response.tfa))
throw response.error.message;
if (response.tfa && response.confirmUrl) {
const url = response.confirmUrl.replace(window.location.origin, "");
return url;
}
api.client.setWithCredentialsStatus(true);
// this.reset();
// this.init();
// const defaultPage = window["AscDesktopEditor"] !== undefined || IS_PERSONAL ? combineUrl(proxyURL, "/products/files/") : "/"
// return this.settingsStore.defaultPage;
return Promise.resolve(response);
} catch (e) {
return Promise.reject(e);
}
}