Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Membership form #7902

Closed
wants to merge 22 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions identity/webapp/pages/api/registration-form.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { generateNewToken, decodeToken } from '../../src/utility/jwt-codec';
import axios from 'axios';
import getConfig from 'next/config';

const { serverRuntimeConfig: config } = getConfig();

export default (req: NextApiRequest, res: NextApiResponse): void => {
if (req.method === 'POST') {
const {
state,
redirectUri,
firstName,
lastName,
termsAndConditions,
sessionToken,
} = req.body;
const { state, firstName, lastName, termsAndConditions, sessionToken } =
req.body;

if (
!state ||
!firstName ||
!lastName ||
!termsAndConditions ||
!sessionToken
) {
res.status(400).json({
error: 'Missing required fields',
});
return;
}

const decodedToken = decodeToken(sessionToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this throws? Something to bikeshed as to whether that's a 401 or a 400

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

co-pilot reckons 400 so I guess that settles it?

const formData = { firstName, lastName, termsAndConditions };

if (typeof decodedToken !== 'string') {
const newToken = generateNewToken(decodedToken, state, formData);

res.redirect(
308,
`${redirectUri}?state=${state}&session_token=${newToken}`
);
axios
.post(`${config.auth0.domain}/continue`, {
state,
session_token: newToken,
})
.then(() => {
res.redirect(302, `/account`);
})
.catch(() => {
res.status(400).json({
error: 'Registration failed',
});
});
}
} else {
res.redirect('/account');
Expand Down