Skip to content

Commit 47abd81

Browse files
author
Vito Chin
committed
Add loginWithState to User service
1 parent e2378b1 commit 47abd81

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/_services/user.service.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { authHeader } from '../_helpers';
33

44
export const userService = {
55
login,
6+
loginWithState,
67
logout,
78
getAll
89
};
@@ -24,6 +25,22 @@ function login(username, password) {
2425
});
2526
}
2627

28+
function loginWithState(state) {
29+
const requestOptions = {
30+
method: 'POST',
31+
headers: { 'Content-Type': 'application/json' },
32+
body: JSON.stringify({ state })
33+
};
34+
return fetch(`${config.apiUrl}/users/stateauth`, requestOptions)
35+
.then(handleResponse)
36+
.then(user => {
37+
// store user details and jwt token in local storage to keep user logged in between page refreshes
38+
localStorage.setItem('user', JSON.stringify(user));
39+
40+
return user;
41+
});
42+
}
43+
2744
function logout() {
2845
// remove user from local storage to log user out
2946
localStorage.removeItem('user');

0 commit comments

Comments
 (0)