Skip to content

Commit

Permalink
chore: made all pages force-dynamic by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoresende committed May 28, 2023
1 parent c4b50b0 commit 2a91da5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion templates/next-graphql/packages/web/app/(entry)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
};
Expand All @@ -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;
Expand All @@ -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 (
Expand Down

0 comments on commit 2a91da5

Please sign in to comment.