Initial commit
This commit is contained in:
commit
fa30c04815
117 changed files with 33513 additions and 0 deletions
38
src/services/auth/hooks/use-auth.ts
Normal file
38
src/services/auth/hooks/use-auth.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { getAuth, signIn, signOut, register as apiRegister, refreshUser as apiRefreshUser } 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 logOut = useCallback(() => {
|
||||
return dispatch(signOut());
|
||||
}, [dispatch]);
|
||||
|
||||
const refreshUser = useCallback(() => {
|
||||
return dispatch(apiRefreshUser());
|
||||
}, [dispatch]);
|
||||
|
||||
return {
|
||||
auth,
|
||||
logIn,
|
||||
logOut,
|
||||
register,
|
||||
refreshUser,
|
||||
};
|
||||
}
|
||||
Reference in a new issue