add login mechanic

This commit is contained in:
2024-01-11 01:00:43 +01:00
parent 6790fe5ef6
commit 05b9ddd5a1
7 changed files with 138 additions and 67 deletions

View File

@@ -1,7 +1,6 @@
import axios from "axios";
import type { Error } from "../types/error";
import type { User } from "../types/user";
import { ipcRenderer } from "electron";
const loginCheckEndpoint = "https://ez-pp.farm/login/check";
let retries = 0;
@@ -9,22 +8,26 @@ let retries = 0;
export const performLogin = async (
username: string,
password: string,
) => {
const result = await ipcRenderer.invoke("ezpplauncher:login", {
username,
password,
): Promise<Error | User> => {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
method: "POST",
mode: "cors",
body: JSON.stringify({ username, password }),
headers: {
"Content-Type": "application/json",
},
});
console.log(result);
return ({ code: 403, message: "Login failed." } as Error);
/* const result = await axios.post(loginCheckEndpoint, { username, password });
const code = result.data.code ?? 404;
if (code === 200 || code === 403) {
if (fetchResult.ok) {
const result = await fetchResult.json();
retries = 0;
return result.data.user as User;
return result.user;
} else {
if (retries++ >= 5) {
return ({ code: 403, message: "Login failed." } as Error);
console.log("Login failed after 5 retries.");
retries = 0;
return { code: 403, message: "Login failed." } as Error;
}
return await performLogin(username, password);
} */
}
};