-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import {USER_LOGIN_MEETHOD} from '../constants/api'; | ||
import {LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAIL} from '../constants/auth'; | ||
import {fetchUser} from './user'; | ||
|
||
export const login = (email, password) => ({ | ||
api: USER_LOGIN_MEETHOD, | ||
data: {email, password}, | ||
types: [LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAIL], | ||
}); | ||
export const login = (email, password) => async (dispatch) => { | ||
const response = await dispatch({ | ||
api: USER_LOGIN_MEETHOD, | ||
data: {email, password}, | ||
types: [LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAIL], | ||
}); | ||
|
||
if (!response.error) { | ||
return dispatch(fetchUser(email)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {USER_SHORT_METHOD} from '../constants/api'; | ||
import {USER_FETCH, USER_FETCH_FAIL, USER_FETCH_SUCCESS} from '../constants/user'; | ||
|
||
export const fetchUser = (email) => ({ | ||
api: USER_SHORT_METHOD, | ||
data: {email}, | ||
types: [USER_FETCH, USER_FETCH_SUCCESS, USER_FETCH_FAIL] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const USER_LOGIN_MEETHOD = 'user/login'; | ||
export const USER_SHORT_METHOD = 'user/short'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const USER_FETCH = 'USER_FETCH'; | ||
export const USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS'; | ||
export const USER_FETCH_FAIL = 'USER_FETCH_FAIL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters