Skip to content

Commit

Permalink
navigate after login/register
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Osman committed Apr 13, 2022
1 parent 13c1bde commit ec9a5db
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/features/auth/AuthScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { memo, useState } from 'react';
import { Link } from 'react-router-dom';
import { useNavigate } from 'react-router';
import { useDispatch, useSelector } from 'react-redux';

import ListErrors from '../../components/ListErrors';
Expand All @@ -18,7 +19,7 @@ function AuthScreen({ isRegisterScreen }) {
const dispatch = useDispatch();
const errors = useSelector(selectErrors);
const inProgress = useSelector(selectIsLoading);

const navigate = useNavigate();
/**
* @type {React.ChangeEventHandler<HTMLInputElement>}
*/
Expand Down Expand Up @@ -50,6 +51,11 @@ function AuthScreen({ isRegisterScreen }) {
? register({ username, email, password })
: login({ email, password })
);
if (isRegisterScreen) {
navigate('/login');
} else {
navigate('/');
}
};

return (
Expand Down

0 comments on commit ec9a5db

Please sign in to comment.