diff --git a/src/app/account/page.tsx b/src/app/account/page.tsx index fe65f5b..8a8a64e 100644 --- a/src/app/account/page.tsx +++ b/src/app/account/page.tsx @@ -7,12 +7,17 @@ import prisma from '@/prisma'; import { ServerActionTrigger } from '@/components/form/serverActionTrigger'; import clearAccountData from '@/lib/actions/clearAccountData'; import { Button } from '@/components/ui/button'; -import { getSession, Session } from '@auth0/nextjs-auth0'; import { URL_SIGN_OUT } from '@/lib/constants'; +import { auth0 } from '@/lib/auth'; +import { redirect } from 'next/navigation'; export default async function AccountPage() { - const {user} = await getSession() as Session; + const session = await auth0.getSession(); + if (!session) { + return redirect('/auth/login'); + } + const user = session.user; let paymentCount = 0; paymentCount = await prisma.payment.count({ diff --git a/src/app/categories/page.tsx b/src/app/categories/page.tsx index e565f55..c2d9334 100644 --- a/src/app/categories/page.tsx +++ b/src/app/categories/page.tsx @@ -3,11 +3,16 @@ import React from 'react'; import CategoryPageClientContent from '@/components/categoryPageClientComponents'; import categoryCreateUpdate from '@/lib/actions/categoryCreateUpdate'; import categoryDelete from '@/lib/actions/categoryDelete'; -import { getSession, Session } from '@auth0/nextjs-auth0'; +import { auth0 } from '@/lib/auth'; +import { redirect } from 'next/navigation'; export default async function CategoriesPage() { - const {user} = await getSession() as Session; + const session = await auth0.getSession(); + if (!session) { + return redirect('/auth/login'); + } + const user = session.user; const categories = await prisma.category.findMany({ where: { diff --git a/src/app/entities/page.tsx b/src/app/entities/page.tsx index 77e694d..660390d 100644 --- a/src/app/entities/page.tsx +++ b/src/app/entities/page.tsx @@ -3,11 +3,16 @@ import React from 'react'; import EntityPageClientContent from '@/components/entityPageClientComponents'; import entityCreateUpdate from '@/lib/actions/entityCreateUpdate'; import entityDelete from '@/lib/actions/entityDelete'; -import { getSession, Session } from '@auth0/nextjs-auth0'; +import { auth0 } from '@/lib/auth'; +import { redirect } from 'next/navigation'; export default async function EntitiesPage() { - const {user} = await getSession() as Session; + const session = await auth0.getSession(); + if (!session) { + return redirect('/auth/login'); + } + const user = session.user; const entities = await prisma.entity.findMany({ where: { diff --git a/src/app/page.tsx b/src/app/page.tsx index bfdb07d..c7b710e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,7 +3,8 @@ import { Category, Entity, EntityType } from '@prisma/client'; import { Scope, ScopeType } from '@/lib/types/scope'; import prisma from '@/prisma'; import DashboardPageClient from '@/components/dashboardPageClientComponents'; -import { getSession, Session } from '@auth0/nextjs-auth0'; +import { auth0 } from '@/lib/auth'; +import { redirect } from 'next/navigation'; export type CategoryNumber = { category: Category, @@ -17,7 +18,11 @@ export type EntityNumber = { export default async function DashboardPage(props: { searchParams?: Promise<{ scope: ScopeType }> }) { - const {user} = await getSession() as Session; + const session = await auth0.getSession(); + if (!session) { + return redirect('/auth/login'); + } + const user = session.user; const scope = Scope.of((await props.searchParams)?.scope || ScopeType.ThisMonth); diff --git a/src/app/payments/page.tsx b/src/app/payments/page.tsx index be795bd..e34a96a 100644 --- a/src/app/payments/page.tsx +++ b/src/app/payments/page.tsx @@ -3,11 +3,16 @@ import React from 'react'; import PaymentPageClientContent from '@/components/paymentPageClientComponents'; import paymentCreateUpdate from '@/lib/actions/paymentCreateUpdate'; import paymentDelete from '@/lib/actions/paymentDelete'; -import { getSession, Session } from '@auth0/nextjs-auth0'; +import { auth0 } from '@/lib/auth'; +import { redirect } from 'next/navigation'; export default async function PaymentsPage() { - const {user} = await getSession() as Session; + const session = await auth0.getSession(); + if (!session) { + return redirect('/auth/login'); + } + const user = session.user; const payments = await prisma.payment.findMany({ where: {