Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyrlex committed Sep 23, 2023
1 parent 67ef368 commit cae73af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 147 deletions.
40 changes: 7 additions & 33 deletions pages/admin/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,6 @@ export default AdminEventsIndex;
export const getServerSideProps = withIronSessionSsr(async function ({ req, resolvedUrl }): Promise<AdminProps<EventDocument>> {
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: {
Expand All @@ -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: {
Expand Down
67 changes: 11 additions & 56 deletions pages/admin/orders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,50 +50,6 @@ export default AdminOrderIndex;
export const getServerSideProps = withIronSessionSsr(async function ({ req, res, resolvedUrl }): Promise<AdminProps<Stripe.PaymentIntent[]>> {
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<Stripe.PaymentIntent[]>;

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: {
Expand All @@ -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<Stripe.PaymentIntent[]>;

console.log(orderResponse);

return {
props: {
props: {
user: req.session.user,
data: orderResponse.data,
},
Expand Down
64 changes: 6 additions & 58 deletions pages/admin/webshop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,6 @@ const AdminProductsIndex: NextPage<Props> = ({ data }) => {
export const getServerSideProps = withIronSessionSsr(async function ({ req, res, resolvedUrl }): Promise<AdminProps<ProductDocument>> {
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<ProductDocument | ProductDocument[]>;

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: {
Expand All @@ -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<ProductDocument | ProductDocument[]>;

return {
props: {
Expand Down

0 comments on commit cae73af

Please sign in to comment.