All checks were successful
gitea-deepak/gog_frontend/pipeline/head This commit looks good
49 lines
950 B
JavaScript
49 lines
950 B
JavaScript
import { API_ROOT } from "./config";
|
|
|
|
export const register = (username, displayName, password) => {
|
|
const url = API_ROOT + "auth/register";
|
|
|
|
const body = {
|
|
username: username,
|
|
display_name: displayName,
|
|
password: password,
|
|
};
|
|
return fetch(url, {
|
|
method: "POST",
|
|
headers: {
|
|
Accept: "application/json",
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
};
|
|
|
|
export const login = (username, password) => {
|
|
const url = API_ROOT + "auth/tokens";
|
|
|
|
const body = {
|
|
username: username,
|
|
password: password,
|
|
};
|
|
return fetch(url, {
|
|
method: "POST",
|
|
headers: {
|
|
Accept: "application/json",
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
})
|
|
.then((response) => {
|
|
if (!response.ok) {
|
|
throw Error(response.statusText);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then((data) => {
|
|
if (data.token) {
|
|
return data.token;
|
|
}
|
|
throw Error("where's my token");
|
|
});
|
|
};
|