diff --git a/apps/nextjs-app/src/features/discussions/components/discussions-list.tsx b/apps/nextjs-app/src/features/discussions/components/discussions-list.tsx
index d532d5c7..acfa384a 100644
--- a/apps/nextjs-app/src/features/discussions/components/discussions-list.tsx
+++ b/apps/nextjs-app/src/features/discussions/components/discussions-list.tsx
@@ -1,5 +1,5 @@
import { useQueryClient } from '@tanstack/react-query';
-import { useRouter } from 'next/router';
+import { useSearchParams } from 'next/navigation';
import { Link } from '@/components/ui/link';
import { Spinner } from '@/components/ui/spinner';
@@ -18,8 +18,8 @@ export type DiscussionsListProps = {
export const DiscussionsList = ({
onDiscussionPrefetch,
}: DiscussionsListProps) => {
- const router = useRouter();
- const page = router.query.page ? Number(router.query.page) : 1;
+ const searchParams = useSearchParams();
+ const page = searchParams?.get('page') ? Number(searchParams.get('page')) : 1;
const discussionsQuery = useDiscussions({
page: page,
diff --git a/apps/nextjs-app/src/lib/api-client.ts b/apps/nextjs-app/src/lib/api-client.ts
index 93131e6e..8455e77a 100644
--- a/apps/nextjs-app/src/lib/api-client.ts
+++ b/apps/nextjs-app/src/lib/api-client.ts
@@ -29,18 +29,6 @@ api.interceptors.response.use(
message,
});
- if (error.response?.status === 401) {
- if (typeof window !== 'undefined') {
- const searchParams = new URLSearchParams();
- const redirectTo = searchParams.get('redirectTo');
- if (redirectTo) {
- window.location.href = `/auth/login?redirectTo=${redirectTo}`;
- } else {
- window.location.href = '/auth/login';
- }
- }
- }
-
return Promise.reject(error);
},
);
diff --git a/apps/nextjs-app/src/lib/auth.tsx b/apps/nextjs-app/src/lib/auth.tsx
index c3288274..aaadba46 100644
--- a/apps/nextjs-app/src/lib/auth.tsx
+++ b/apps/nextjs-app/src/lib/auth.tsx
@@ -1,4 +1,6 @@
-import { useRouter } from 'next/router';
+'use client';
+
+import { usePathname, useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { configureAuth } from 'react-query-auth';
import { z } from 'zod';
@@ -78,14 +80,19 @@ export const { useUser, useLogin, useLogout, useRegister, AuthLoader } =
export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
const user = useUser();
const router = useRouter();
+ const pathname = usePathname();
useEffect(() => {
if (!user.data) {
- router.replace(
- `/auth/login?redirectTo=${encodeURIComponent(router.pathname)}`,
- );
+ if (pathname) {
+ router.replace(
+ `/auth/login?redirectTo=${encodeURIComponent(pathname)}`,
+ );
+ } else {
+ router.replace('/auth/login');
+ }
}
- }, [user.data, router]);
+ }, [user.data, router, pathname]);
return children;
};
diff --git a/apps/nextjs-app/src/lib/authorization.tsx b/apps/nextjs-app/src/lib/authorization.tsx
index fbf094a2..72297b75 100644
--- a/apps/nextjs-app/src/lib/authorization.tsx
+++ b/apps/nextjs-app/src/lib/authorization.tsx
@@ -1,4 +1,6 @@
-import { useRouter } from 'next/router';
+'use client';
+
+import { usePathname, useRouter } from 'next/navigation';
import * as React from 'react';
import { Comment, User } from '@/types/api';
@@ -29,10 +31,11 @@ export const POLICIES = {
export const useAuthorization = () => {
const user = useUser();
const router = useRouter();
+ const pathname = usePathname();
if (!user.data && !user.isLoading) {
- const redirectTo = encodeURIComponent(router.pathname);
- window.location.href = `/auth/login?redirectTo=${redirectTo}`;
+ const redirectTo = encodeURIComponent(pathname);
+ router.push(`/auth/login?redirectTo=${redirectTo}`);
}
const checkAccess = React.useCallback(
diff --git a/apps/nextjs-app/src/pages/_app.tsx b/apps/nextjs-app/src/pages/_app.tsx
deleted file mode 100644
index 90852dcf..00000000
--- a/apps/nextjs-app/src/pages/_app.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { NextPage } from 'next';
-import type { AppProps } from 'next/app';
-import { ReactElement, ReactNode } from 'react';
-
-import { AppProvider } from '@/app/provider';
-
-import '@/styles/globals.css';
-
-// eslint-disable-next-line @typescript-eslint/ban-types
-export type NextPageWithLayout
= NextPage
& {
- getLayout?: (page: ReactElement) => ReactNode;
-};
-
-type AppPropsWithLayout = AppProps & {
- Component: NextPageWithLayout;
-};
-
-export default function App({ Component, pageProps }: AppPropsWithLayout) {
- const getLayout = Component.getLayout ?? ((page) => page);
- return {getLayout()};
-}
diff --git a/apps/nextjs-app/src/pages/app/discussions/[discussionId].tsx b/apps/nextjs-app/src/pages/app/discussions/[discussionId].tsx
deleted file mode 100644
index 4dda5581..00000000
--- a/apps/nextjs-app/src/pages/app/discussions/[discussionId].tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { DiscussionPage as default } from '@/app/pages/app/discussions/discussion';
diff --git a/apps/nextjs-app/src/pages/app/discussions/index.tsx b/apps/nextjs-app/src/pages/app/discussions/index.tsx
deleted file mode 100644
index baad9a2a..00000000
--- a/apps/nextjs-app/src/pages/app/discussions/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { DiscussionsPage as default } from '@/app/pages/app/discussions/discussions';
diff --git a/apps/nextjs-app/src/pages/app/index.tsx b/apps/nextjs-app/src/pages/app/index.tsx
deleted file mode 100644
index 56da8442..00000000
--- a/apps/nextjs-app/src/pages/app/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { DashboardPage as default } from '@/app/pages/app/dashboard';
diff --git a/apps/nextjs-app/src/pages/app/profile.tsx b/apps/nextjs-app/src/pages/app/profile.tsx
deleted file mode 100644
index 64b53045..00000000
--- a/apps/nextjs-app/src/pages/app/profile.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { ProfilePage as default } from '@/app/pages/app/profile';
diff --git a/apps/nextjs-app/src/pages/app/users.tsx b/apps/nextjs-app/src/pages/app/users.tsx
deleted file mode 100644
index f7bffe43..00000000
--- a/apps/nextjs-app/src/pages/app/users.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { UsersPage as default } from '@/app/pages/app/users';
diff --git a/apps/nextjs-app/src/pages/auth/login.tsx b/apps/nextjs-app/src/pages/auth/login.tsx
deleted file mode 100644
index 21170557..00000000
--- a/apps/nextjs-app/src/pages/auth/login.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { LoginPage as default } from '@/app/pages/auth/login';
diff --git a/apps/nextjs-app/src/pages/auth/register.tsx b/apps/nextjs-app/src/pages/auth/register.tsx
deleted file mode 100644
index 2fa77b12..00000000
--- a/apps/nextjs-app/src/pages/auth/register.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { RegisterPage as default } from '@/app/pages/auth/register';
diff --git a/apps/nextjs-app/src/pages/index.tsx b/apps/nextjs-app/src/pages/index.tsx
deleted file mode 100644
index dbe1e60b..00000000
--- a/apps/nextjs-app/src/pages/index.tsx
+++ /dev/null
@@ -1,89 +0,0 @@
-import { useRouter } from 'next/router';
-
-import { Head } from '@/components/seo';
-import { Button } from '@/components/ui/button';
-import { useUser } from '@/lib/auth';
-
-export const HomePage = () => {
- const router = useRouter();
- const user = useUser();
-
- const handleStart = () => {
- if (user.data) {
- router.push('/app');
- } else {
- router.push('/auth/login');
- }
- };
-
- return (
- <>
-
-