Skip to content

Commit

Permalink
prevent circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
alan2207 committed May 3, 2024
1 parent 4f17226 commit 17beb80
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 36 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
patterns: ['@/features/*/*'],
},
],
'import/no-cycle': 'error',
'linebreak-style': ['error', 'unix'],
'react/prop-types': 'off',
'import/order': [
Expand Down
3 changes: 1 addition & 2 deletions src/components/Layout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import * as React from 'react';
import { NavLink, Link } from 'react-router-dom';

import logo from '@/assets/logo.svg';
import { useLogout } from '@/lib/auth';
import { useAuthorization, ROLES } from '@/lib/authorization';
import { useLogout, useAuthorization, ROLES } from '@/features/auth';

type SideNavigationItem = {
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as z from 'zod';

import { Button } from '@/components/Elements';
import { Form, InputField } from '@/components/Form';
import { useLogin } from '@/lib/auth';

import { useLogin } from '../lib/auth';

const schema = z.object({
email: z.string().min(1, 'Required'),
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/components/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as z from 'zod';
import { Button } from '@/components/Elements';
import { Form, InputField, SelectField } from '@/components/Form';
import { useTeams } from '@/features/teams';
import { useRegister } from '@/lib/auth';

import { useRegister } from '../lib/auth';

const schema = z
.object({
Expand Down
6 changes: 2 additions & 4 deletions src/features/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export * from './api/getUser';
export * from './api/login';
export * from './api/register';
export * from './api/logout';
export * from './lib/auth';
export * from './lib/authorization';

export * from './routes';

Expand Down
File renamed without changes.
14 changes: 5 additions & 9 deletions src/lib/auth.tsx → src/features/auth/lib/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { configureAuth } from 'react-query-auth';

import {
loginWithEmailAndPassword,
getUser,
registerWithEmailAndPassword,
UserResponse,
LoginCredentialsDTO,
RegisterCredentialsDTO,
logout,
} from '@/features/auth';
import { getUser } from '../api/getUser';
import { LoginCredentialsDTO, loginWithEmailAndPassword } from '../api/login';
import { logout } from '../api/logout';
import { RegisterCredentialsDTO, registerWithEmailAndPassword } from '../api/register';
import { UserResponse } from '../types';

async function handleUserResponse(data: UserResponse) {
const { user } = data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { Comment } from '@/features/comments';
import { User } from '@/features/users';
import { type Comment } from '@/features/comments';
import { type User } from '@/features/users';

import { useUser } from './auth';

Expand Down
3 changes: 1 addition & 2 deletions src/features/comments/components/CommentsList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ArchiveBoxIcon } from '@heroicons/react/16/solid';

import { Spinner, MDPreview } from '@/components/Elements';
import { useUser, POLICIES, Authorization } from '@/features/auth';
import { User } from '@/features/users';
import { useUser } from '@/lib/auth';
import { POLICIES, Authorization } from '@/lib/authorization';
import { formatDate } from '@/utils/format';

import { useComments } from '../api/getComments';
Expand Down
2 changes: 1 addition & 1 deletion src/features/discussions/components/CreateDiscussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as z from 'zod';

import { Button } from '@/components/Elements';
import { Form, FormDrawer, InputField, TextAreaField } from '@/components/Form';
import { Authorization, ROLES } from '@/lib/authorization';
import { Authorization, ROLES } from '@/features/auth';

import { CreateDiscussionDTO, useCreateDiscussion } from '../api/createDiscussion';

Expand Down
2 changes: 1 addition & 1 deletion src/features/discussions/components/DeleteDiscussion.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TrashIcon } from '@heroicons/react/16/solid';

import { Button, ConfirmationDialog } from '@/components/Elements';
import { Authorization, ROLES } from '@/lib/authorization';
import { Authorization, ROLES } from '@/features/auth';

import { useDeleteDiscussion } from '../api/deleteDiscussion';

Expand Down
2 changes: 1 addition & 1 deletion src/features/discussions/components/UpdateDiscussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as z from 'zod';

import { Button } from '@/components/Elements';
import { Form, FormDrawer, InputField, TextAreaField } from '@/components/Form';
import { Authorization, ROLES } from '@/lib/authorization';
import { Authorization, ROLES } from '@/features/auth';

import { useDiscussion } from '../api/getDiscussion';
import { UpdateDiscussionDTO, useUpdateDiscussion } from '../api/updateDiscussion';
Expand Down
3 changes: 1 addition & 2 deletions src/features/misc/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ContentLayout } from '@/components/Layout';
import { useUser } from '@/lib/auth';
import { ROLES } from '@/lib/authorization';
import { useUser, ROLES } from '@/features/auth';

export const Dashboard = () => {
const user = useUser();
Expand Down
2 changes: 1 addition & 1 deletion src/features/misc/routes/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router';
import logo from '@/assets/logo.svg';
import { Button } from '@/components/Elements';
import { Head } from '@/components/Head';
import { useUser } from '@/lib/auth';
import { useUser } from '@/features/auth';

export const Landing = () => {
const navigate = useNavigate();
Expand Down
2 changes: 1 addition & 1 deletion src/features/users/api/updateProfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation } from '@tanstack/react-query';

import { useUser } from '@/lib/auth';
import { useUser } from '@/features/auth';
import { axios } from '@/lib/axios';
import { MutationConfig } from '@/lib/react-query';
import { useNotificationStore } from '@/stores/notifications';
Expand Down
2 changes: 1 addition & 1 deletion src/features/users/components/DeleteUser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, ConfirmationDialog } from '@/components/Elements';
import { useUser } from '@/lib/auth';
import { useUser } from '@/features/auth';

import { useDeleteUser } from '../api/deleteUser';

Expand Down
2 changes: 1 addition & 1 deletion src/features/users/components/UpdateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as z from 'zod';

import { Button } from '@/components/Elements';
import { Form, FormDrawer, InputField, TextAreaField } from '@/components/Form';
import { useUser } from '@/lib/auth';
import { useUser } from '@/features/auth';

import { UpdateProfileDTO, useUpdateProfile } from '../api/updateProfile';

Expand Down
2 changes: 1 addition & 1 deletion src/features/users/routes/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentLayout } from '@/components/Layout';
import { useUser } from '@/lib/auth';
import { useUser } from '@/features/auth';

import { UpdateProfile } from '../components/UpdateProfile';

Expand Down
2 changes: 1 addition & 1 deletion src/features/users/routes/Users.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentLayout } from '@/components/Layout';
import { Authorization, ROLES } from '@/lib/authorization';
import { Authorization, ROLES } from '@/features/auth';

import { UsersList } from '../components/UsersList';

Expand Down
3 changes: 1 addition & 2 deletions src/providers/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { BrowserRouter as Router } from 'react-router-dom';

import { Button, Spinner } from '@/components/Elements';
import { Notifications } from '@/components/Notifications/Notifications';
// import { AuthLoader } from '@/lib/auth';
import { AuthLoader } from '@/lib/auth';
import { AuthLoader } from '@/features/auth';
import { queryConfig } from '@/lib/react-query';

const ErrorFallback = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRoutes } from 'react-router-dom';

import { useUser } from '@/features/auth';
import { Landing } from '@/features/misc';
import { useUser } from '@/lib/auth';

import { protectedRoutes } from './protected';
import { publicRoutes } from './public';
Expand Down
1 change: 0 additions & 1 deletion src/test/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export function requireAuth(cookies: Record<string, string>, shouldThrow = true)
try {
// todo: fix once tests in Github Actions are fixed
// const encodedToken = cookies[AUTH_COOKIE];
console.log('cookies', cookies);
const encodedToken = Cookies.get(AUTH_COOKIE);
if (!encodedToken) {
if (shouldThrow) {
Expand Down

0 comments on commit 17beb80

Please sign in to comment.