Feat/login
This commit is contained in:
parent
4803c4d8b6
commit
3361d4c043
7 changed files with 91 additions and 167 deletions
|
|
@ -1,38 +1,22 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { getAuth, signIn, signOut, register as apiRegister, refreshUser as apiRefreshUser } from '../redux';
|
||||
import { getAuth, signIn, signOut } from '../redux';
|
||||
|
||||
export function useAuth() {
|
||||
const dispatch = useDispatch();
|
||||
const auth = useSelector(getAuth);
|
||||
|
||||
const logIn = useCallback(
|
||||
(email: string, password: string) => {
|
||||
return dispatch(signIn(email, password));
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
|
||||
const register = useCallback(
|
||||
(email: string, password: string, firstName: string, lastName: string) => {
|
||||
return dispatch(apiRegister(email, password, firstName, lastName));
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
const logIn = useCallback(() => {
|
||||
return dispatch(signIn());
|
||||
}, [dispatch]);
|
||||
|
||||
const logOut = useCallback(() => {
|
||||
return dispatch(signOut());
|
||||
}, [dispatch]);
|
||||
|
||||
const refreshUser = useCallback(() => {
|
||||
return dispatch(apiRefreshUser());
|
||||
}, [dispatch]);
|
||||
|
||||
return {
|
||||
auth,
|
||||
logIn,
|
||||
logOut,
|
||||
register,
|
||||
refreshUser,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue