2023-05-17 13:18:26 +00:00
|
|
|
import { User } from "@root/model/auth";
|
2023-05-17 11:20:11 +00:00
|
|
|
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;
|
|
|
|
|
2023-05-17 15:26:10 +00:00
|
|
|
export async function getOrCreateUser(userId: string): Promise<User | null> {
|
2023-05-17 13:18:26 +00:00
|
|
|
return makeRequest<never, User>({
|
|
|
|
url: `${apiUrl}/${userId}`,
|
|
|
|
contentType: true,
|
|
|
|
method: "GET",
|
|
|
|
useToken: false,
|
|
|
|
withCredentials: false,
|
|
|
|
});
|
2023-05-17 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function logout() {
|
|
|
|
return makeRequest<never, void>({
|
|
|
|
url: authUrl + "/logout",
|
|
|
|
method: "POST",
|
|
|
|
useToken: false,
|
|
|
|
withCredentials: true,
|
|
|
|
});
|
|
|
|
}
|