import { base, getToken } from "./_config";

export async function createToken({ username=null, password=null }) {
    const res = await fetch(`${base}/auth/`, {
        method: 'POST',
        body: JSON.stringify({ username, password }),
        headers: { "Content-Type": "application/json" }
    })
    if (!res.ok) throw await res.text()
    return res.json()
}

export async function getInfoToken() {
    const res = await fetch(`${base}/auth/`, {
        headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
    })
    if (!res.ok) throw await res.text()
    return res.json()
}