Skip to content

Commit

Permalink
feature #12: Add login to User Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Boosmith committed Aug 29, 2019
1 parent e010389 commit c1d531a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/authApi copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { handleResponse, handleError } from "./apiUtils";
const baseUrl = process.env.REACT_APP_API_URL + "/api/auth/";

export function login(userName, password) {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userName, password })
};

return fetch(requestOptions);
}
15 changes: 15 additions & 0 deletions src/api/userApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ export function getOneUser(userId) {
.catch(handleError);
}

export function login(userName, password) {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userName, password })
};

return fetch(baseUrl + "/authenticate", requestOptions)
.then(handleResponse)
.then(user => {
localStorage.setItem("trelloid_jwt_token", JSON.stringify(user.token));
})
.catch(handleError);
}

export function saveUser(user) {
return fetch(baseUrl + (user._id || ""), {
method: user._id ? "PUT" : "POST",
Expand Down

0 comments on commit c1d531a

Please sign in to comment.