Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyrlex committed Oct 3, 2023
1 parent 7222518 commit b4b2083
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 81 deletions.
39 changes: 1 addition & 38 deletions pages/admin/sponsors/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const AdminCreateSponsors: NextPage<{ user: { email: string, has2faEnabled: bool
url: data.url,
}),
});

if (req.ok) {
console.log('ok');
} else if (req.status === 401) {
Expand Down Expand Up @@ -91,31 +91,6 @@ const AdminCreateSponsors: NextPage<{ user: { email: string, has2faEnabled: bool
export const getServerSideProps = withIronSessionSsr(async function ({ req, resolvedUrl }): Promise<AdminProps> {
const user = req?.session.user;

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: '',
},
};
}

if (!user) {
return {
props: {
Expand All @@ -128,18 +103,6 @@ export const getServerSideProps = withIronSessionSsr(async function ({ req, reso
};
}

if (!user.has2faEnabled) {
return {
props: {
user: { email: user.email, has2faEnabled: false, completed2fa: false },
},
redirect: {
destination: '/admin/settings',
permanent: false,
},
};
}

return {
props: { user: req.session.user },
};
Expand Down
44 changes: 1 addition & 43 deletions pages/admin/sponsors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InProgress from '../../../components/InProgress';
import { AdminProps } from '../../../src/types/index';
import { SponsorDocument } from '../../../src/models/Sponsor';

const AdminSponsorsIndex: NextPage =() => {
const AdminSponsorsIndex: NextPage = () => {
return (
<InProgress pageName='sponsors'></InProgress>
);
Expand All @@ -26,36 +26,6 @@ export const getServerSideProps = withIronSessionSsr(async function ({ req, res,

const data = await request.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: data.data,
},
};
}

if (!user) {
return {
props: {
Expand All @@ -68,18 +38,6 @@ 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,
},
};
}

return {
props: {
user: req.session.user,
Expand Down

0 comments on commit b4b2083

Please sign in to comment.