MCPcopy
hub / github.com/chartbrew/chartbrew / login

Function login

client/src/actions/user.js:265–291  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

263}
264
265export function login(data) {
266 const headers = new Headers({
267 "Accept": "application/json",
268 "Content-Type": "application/json",
269 });
270 const body = JSON.stringify(data);
271 return (dispatch) => {
272 return fetch(`${API_HOST}/user/login`, { method: "POST", headers, body })
273 .then((response) => {
274 if (!response.ok) {
275 dispatch(addError(response.status, "Couldn't login"));
276 throw new Error("Couldn't login");
277 }
278 return response.json();
279 })
280 .then(user => {
281 // save the cookie here
282 if (cookie.load("brewToken")) cookie.remove("brewToken", { path: "/" });
283 cookie.save("brewToken", user.token, { expires, path: "/" });
284 dispatch(saveUser(user));
285 return new Promise(resolve => resolve(user));
286 })
287 .catch(err => {
288 return new Promise((resolve, reject) => reject(err.message));
289 });
290 };
291}
292
293export function relog() {
294 const token = cookie.load("brewToken");

Callers 1

handleLoginFunction · 0.90

Calls 4

addErrorFunction · 0.90
saveUserFunction · 0.85
dispatchFunction · 0.50
removeMethod · 0.45

Tested by

no test coverage detected