import { CreateUserRequest, User } from "@root/model/auth"; import { authStore } from "@root/stores/makeRequest"; const apiUrl = process.env.NODE_ENV === "production" ? "/user" : "https://hub.pena.digital/user"; const authUrl = process.env.NODE_ENV === "production" ? "/auth" : "https://hub.pena.digital/auth"; const makeRequest = authStore.getState().makeRequest; export async function getOrCreateUser({ userId, email, password }: { userId: string; email: string | null; password: string | null; }): Promise { try { return await makeRequest({ url: `${apiUrl}/${userId}`, contentType: true, method: "GET", useToken: false, withCredentials: false, }); } catch (error) { console.log("get user error", error); if (!email || !password) return null; return makeRequest({ url: apiUrl, contentType: true, method: "POST", useToken: true, withCredentials: false, body: { email, login: email, password, phoneNumber: "-", } }); } } export function logout() { return makeRequest({ url: authUrl + "/logout", method: "POST", useToken: false, withCredentials: true, }); }