databag/net/web/src/api/addAccount.js
2022-07-29 14:23:02 -07:00

16 lines
528 B
JavaScript

import { checkResponse, fetchWithCustomTimeout } from './fetchUtil';
var base64 = require('base-64');
export async function addAccount(username, password, token) {
let access = "";
if (token) {
access = `?token=${token}`
}
let headers = new Headers()
headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password));
let profile = await fetchWithCustomTimeout(`/account/profile${access}`, { method: 'POST', headers: headers }, 60000)
checkResponse(profile);
return await profile.json()
}