Skip to content

Commit

Permalink
refactor: delete useAuth hook
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitCode committed Nov 1, 2024
1 parent 2d87c09 commit 9d746dd
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 39 deletions.
11 changes: 4 additions & 7 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Outlet } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import Header from './components/Header';
import { AuthProvider } from './contexts/AuthContext';

const App = () => (
<>
<ToastContainer
autoClose={2000}
draggable
/>
<AuthProvider>
<div className="d-flex flex-column h-100">
<Header />
<Outlet />
</div>
</AuthProvider>
<div className="d-flex flex-column h-100">
<Header />
<Outlet />
</div>
</>
);

Expand Down
23 changes: 0 additions & 23 deletions frontend/src/contexts/AuthContext.js

This file was deleted.

3 changes: 0 additions & 3 deletions frontend/src/pages/LoginPage/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { Button, Form } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useFormik } from 'formik';
import { toast } from 'react-toastify';
import { useAuth } from '../../store/hooks/hooks';
import { setUserData } from '../../store/slices/authSlice';
import { useLoginMutation } from '../../api/authApi';
import { ROOT_PATH, getRoutesPath } from '../../router/routesPath';

const LoginForm = () => {
const auth = useAuth();
const navigate = useNavigate();
const dispatch = useDispatch();
const [authFailed, setAuthFailed] = useState(false);
Expand All @@ -33,7 +31,6 @@ const LoginForm = () => {
try {
const data = await login(values).unwrap();
dispatch(setUserData(data));
auth.logIn();
navigate(getRoutesPath(ROOT_PATH));
} catch (err) {
if (err.status === 401) {
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/pages/SignUpPage/SignUpForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { useRef } from 'react';
import { object, string, ref } from 'yup';
import { toast } from 'react-toastify';
import { useSignupMutation } from '../../api/authApi';
import { useAuth } from '../../store/hooks/hooks';
import { setUserData } from '../../store/slices/authSlice';
import { ROOT_PATH, getRoutesPath } from '../../router/routesPath';

const SignUpForm = () => {
const auth = useAuth();
const navigate = useNavigate();
const dispatch = useDispatch();
const inputRef = useRef();
Expand All @@ -36,7 +34,6 @@ const SignUpForm = () => {
try {
const data = await signup(values).unwrap();
dispatch(setUserData(data));
auth.logIn();
navigate(getRoutesPath(ROOT_PATH));
} catch (err) {
if (err.status === 409) {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/store/hooks/hooks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useContext } from 'react';
import { AuthContext } from '../../contexts/AuthContext';
import { SocketContext } from '../../contexts/SocketContext';

const useAuth = () => useContext(AuthContext);
const useSocket = () => useContext(SocketContext);

export { useAuth, useSocket };
export default useSocket;

0 comments on commit 9d746dd

Please sign in to comment.