File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { authHeader } from '../_helpers';
3
3
4
4
export const userService = {
5
5
login,
6
+ loginWithState,
6
7
logout,
7
8
getAll
8
9
} ;
@@ -24,6 +25,22 @@ function login(username, password) {
24
25
} ) ;
25
26
}
26
27
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
+
27
44
function logout ( ) {
28
45
// remove user from local storage to log user out
29
46
localStorage . removeItem ( 'user' ) ;
You can’t perform that action at this time.
0 commit comments