Initial commit
This commit is contained in:
commit
fa30c04815
117 changed files with 33513 additions and 0 deletions
56
src/services/auth/redux/actions.ts
Normal file
56
src/services/auth/redux/actions.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { createApiAction } from 'src/services/api';
|
||||
import { SuccessAction } from 'src/services/api/redux/types';
|
||||
|
||||
export enum AuthActionTypes {
|
||||
SIGN_IN_START = 'auth/sign_in_start',
|
||||
SIGN_IN_SUCCESS = 'auth/sign_in_success',
|
||||
SIGN_IN_FAILURE = 'auth/sign_in_failure',
|
||||
SIGN_OUT = 'auth/SIGN_OUT',
|
||||
REGISTRATION_START = 'auth/registration_start',
|
||||
REGISTRATION_FAILURE = 'auth/registration_failure',
|
||||
}
|
||||
|
||||
const signOutAction = (): SuccessAction => ({
|
||||
type: AuthActionTypes.SIGN_OUT,
|
||||
payload: null,
|
||||
});
|
||||
|
||||
export const signIn = (email: string, password: string) =>
|
||||
createApiAction(
|
||||
{
|
||||
path: '/login',
|
||||
method: 'POST',
|
||||
body: { username: email, password },
|
||||
},
|
||||
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
|
||||
);
|
||||
|
||||
export const refreshUser = () =>
|
||||
createApiAction(
|
||||
{
|
||||
path: '/dashboard',
|
||||
method: 'GET',
|
||||
},
|
||||
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
|
||||
);
|
||||
|
||||
export function signOut() {
|
||||
return (dispatch: any) => {
|
||||
dispatch(signOutAction());
|
||||
};
|
||||
}
|
||||
|
||||
export const register = (email: string, password: string, firstName: string, lastName: string) =>
|
||||
createApiAction(
|
||||
{
|
||||
path: '/auth/register',
|
||||
method: 'POST',
|
||||
body: {
|
||||
email,
|
||||
firstName,
|
||||
lastName,
|
||||
password,
|
||||
},
|
||||
},
|
||||
[AuthActionTypes.REGISTRATION_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.REGISTRATION_FAILURE],
|
||||
);
|
||||
Reference in a new issue