Initial commit

This commit is contained in:
Luka Radenovic 2021-09-27 12:17:33 +02:00
commit fa30c04815
117 changed files with 33513 additions and 0 deletions

View 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,
};
}