From 2a91da56035c98894f5b6479f1e963fd751fdae5 Mon Sep 17 00:00:00 2001 From: Ernesto Resende Date: Sun, 28 May 2023 01:43:10 -0300 Subject: [PATCH] chore: made all pages force-dynamic by default --- .../packages/web/app/(entry)/page.tsx | 3 ++- .../packages/web/app/(entry)/protected/page.tsx | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/templates/next-graphql/packages/web/app/(entry)/page.tsx b/templates/next-graphql/packages/web/app/(entry)/page.tsx index 77ca230..077a95b 100644 --- a/templates/next-graphql/packages/web/app/(entry)/page.tsx +++ b/templates/next-graphql/packages/web/app/(entry)/page.tsx @@ -19,11 +19,12 @@ import { QueryBox } from '@/components/query-box'; * @see https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering#using-dynamic-data-fetches * @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic */ + const makeClient = () => { const client = createClient({ url: `${getBaseUrl()}/api/graphql`, fetch: fetch, - next: { revalidate: 60 }, + cache: 'no-store', }); return client; diff --git a/templates/next-graphql/packages/web/app/(entry)/protected/page.tsx b/templates/next-graphql/packages/web/app/(entry)/protected/page.tsx index 6aaa4d7..97bcfc1 100644 --- a/templates/next-graphql/packages/web/app/(entry)/protected/page.tsx +++ b/templates/next-graphql/packages/web/app/(entry)/protected/page.tsx @@ -1,15 +1,17 @@ import React from 'react'; import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; -import { createClient, getBaseUrl, registerClient } from '@/utils/graphql'; +import { + createClient, + getBaseUrl, + registerClient, +} from '@/utils/graphql'; import { auth } from '@acme/auth'; import { Hero } from '@/components/hero'; import { LogoutButton } from '@/components/logout'; import { QueryBox } from '@/components/query-box'; -export const dynamic = 'force-dynamic'; - export const metadata = { title: 'Protected', }; @@ -18,9 +20,10 @@ const makeClient = () => { const client = createClient({ url: `${getBaseUrl()}/api/graphql`, fetch: fetch, + cache: 'no-store', headers: { Authorization: `Bearer ${cookies().get('auth_session')?.value}`, - }, + } }); return client; @@ -29,13 +32,13 @@ const makeClient = () => { const { getClient } = registerClient(makeClient); export default async function IndexPage() { - //@ts-ignore const authRequest = auth.handleRequest({ cookies }); const { user } = await authRequest.validateUser(); + if (!user) redirect('/login'); const data = await getClient().query({ - protected: true, + authorizedOnly: true, }); return (