aboutsummaryrefslogtreecommitdiff
path: root/src/pages/AuthPage/SignInForm.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/AuthPage/SignInForm.tsx')
-rw-r--r--src/pages/AuthPage/SignInForm.tsx15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx
index 1dad153..e68483b 100644
--- a/src/pages/AuthPage/SignInForm.tsx
+++ b/src/pages/AuthPage/SignInForm.tsx
@@ -6,10 +6,8 @@ import {
FormControlLabel,
Switch
} from '@material-ui/core';
-
-interface PropTypes {
- logIn: (name: string, password: string, remember?: boolean) => Promise<boolean>;
-}
+import { useAuth } from '../../hooks/useAuth';
+import { useNavigate } from '../../hooks/useNavigate';
const useStyles = makeStyles(theme => ({
root: {
@@ -28,12 +26,14 @@ const useStyles = makeStyles(theme => ({
}
}));
-const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
+const SignInForm: React.FC = () => {
const [error, setError] = useState<boolean>(false);
const [remember, setRemember] = useState<boolean>(true);
const classes = useStyles();
const nameRef = useRef<HTMLInputElement>();
const passwordRef = useRef<HTMLInputElement>();
+ const { login } = useAuth();
+ const { navigate } = useNavigate();
const handleCheck = () => {
setRemember(!remember);
@@ -43,8 +43,9 @@ const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
const name = nameRef.current?.value;
const password = passwordRef.current?.value;
if (name && password) {
- logIn(name, password, remember).then(success => {
- if (!success) setError(true);
+ login(name, password, remember).then(success => {
+ if (success) navigate('profile');
+ else setError(true);
});
}
};