export let authHeader : any = {};

export const serverBaseUrl = import.meta.env.VITE_SERVER_URL;

export const authBase = "auth";
export const authRegister = "register";

export async function register() {
    console.log("Registering at server.")
    if (Object.entries(authHeader).length === 0) {
        return fetch(`${serverBaseUrl}/${authBase}/${authRegister}`, {
            method: "POST", 
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({'client': 'dash'})
        })
        .then(response => response.json())
        .then(data => { authHeader = {
            'Authorization': `Bearer ${data}`,
            'X-JWT': `Bearer ${data}`,
        }; });
    }
}
