From cae73afd4bad6935017694c593c28f4a533e215b Mon Sep 17 00:00:00 2001 From: Jaren Goldberg Date: Sat, 23 Sep 2023 15:51:01 -0400 Subject: [PATCH] fix --- pages/admin/events/index.tsx | 40 ++++----------------- pages/admin/orders/index.tsx | 67 ++++++----------------------------- pages/admin/webshop/index.tsx | 64 ++++----------------------------- 3 files changed, 24 insertions(+), 147 deletions(-) diff --git a/pages/admin/events/index.tsx b/pages/admin/events/index.tsx index b40114e..adb67af 100644 --- a/pages/admin/events/index.tsx +++ b/pages/admin/events/index.tsx @@ -52,39 +52,6 @@ export default AdminEventsIndex; export const getServerSideProps = withIronSessionSsr(async function ({ req, resolvedUrl }): Promise> { const user = req.session.user; - const eventRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/events`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' }, - }); - - const eventResponse = await eventRequest.json(); - - if (user?.email) { - const request = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/auth/2fa/generate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(user), - }); - - const json = await request.json(); - - if (json.data) return { - props: { - user: { email: user.email, has2faEnabled: true, completed2fa: false }, - otpAuthUri: json.data, - }, - }; - return { - props: { - user: { email: user.email, has2faEnabled: false, completed2fa: false }, - otpAuthUri: '', - data: eventResponse.data, - }, - }; - } - if (!user) { return { props: { @@ -97,6 +64,13 @@ export const getServerSideProps = withIronSessionSsr(async function ({ req, reso }; } + const eventRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/events`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + const eventResponse = await eventRequest.json(); + if (!user.has2faEnabled) { return { props: { diff --git a/pages/admin/orders/index.tsx b/pages/admin/orders/index.tsx index 50f5e9e..855f24b 100644 --- a/pages/admin/orders/index.tsx +++ b/pages/admin/orders/index.tsx @@ -50,50 +50,6 @@ export default AdminOrderIndex; export const getServerSideProps = withIronSessionSsr(async function ({ req, res, resolvedUrl }): Promise> { const user = req.session.user; - res?.setHeader( - 'Cache-Control', - 'public, s-maxage=10, stale-while-revalidate=59', - ); - - const payoutRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/stripe/orders`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - - const orderResponse = await payoutRequest.json() as ResponseData; - - console.log(orderResponse); - - - if (user?.email) { - const request = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/auth/2fa/generate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(user), - }); - - const json = await request.json(); - - if (json.data) return { - props: { - user: { email: user.email, has2faEnabled: true, completed2fa: false }, - otpAuthUri: json.data, - }, - }; - - return { - props: { - user: { email: user.email, has2faEnabled: false, completed2fa: false }, - otpAuthUri: '', - data: orderResponse.data, - }, - }; - } - if (!user) { return { props: { @@ -106,20 +62,19 @@ export const getServerSideProps = withIronSessionSsr(async function ({ req, res, }; } - if (!user.has2faEnabled) { - return { - props: { - user: { email: user.email, has2faEnabled: false, completed2fa: false }, - }, - redirect: { - destination: '/admin/settings', - permanent: false, - }, - }; - } + const payoutRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/stripe/orders`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + const orderResponse = await payoutRequest.json() as ResponseData; + + console.log(orderResponse); return { - props: { + props: { user: req.session.user, data: orderResponse.data, }, diff --git a/pages/admin/webshop/index.tsx b/pages/admin/webshop/index.tsx index 1995a5f..8666421 100644 --- a/pages/admin/webshop/index.tsx +++ b/pages/admin/webshop/index.tsx @@ -47,49 +47,6 @@ const AdminProductsIndex: NextPage = ({ data }) => { export const getServerSideProps = withIronSessionSsr(async function ({ req, res, resolvedUrl }): Promise> { const user = req?.session.user; - res?.setHeader( - 'Cache-Control', - 'public, s-maxage=10, stale-while-revalidate=59', - ); - - const productRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/products`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' }, - }); - - const productData = await productRequest.json() as ResponseData; - - if (user?.email) { - const request2FA = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/auth/2fa/generate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(user), - }); - - const json = await request2FA.json(); - - if (json.data) return { - props: { - user: { email: user.email, has2faEnabled: true, completed2fa: false }, - otpAuthUri: json.data, - }, - }; - - return { - props: { - user: { - email: user.email, - has2faEnabled: false, - completed2fa: false, - }, - otpAuthUri: '', - data: productData.data, - }, - }; - } - if (!user) { return { props: { @@ -102,21 +59,12 @@ export const getServerSideProps = withIronSessionSsr(async function ({ req, res, }; } - if (!user.has2faEnabled) { - return { - props: { - user: { - email: user.email, - has2faEnabled: false, - completed2fa: false, - }, - }, - redirect: { - destination: '/admin/settings', - permanent: false, - }, - }; - } + const productRequest = await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}/api/products`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + const productData = await productRequest.json() as ResponseData; return { props: {