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

Membership form #7902

wants to merge 22 commits into from

Conversation

davidpmccormick
Copy link
Contributor

@davidpmccormick davidpmccormick commented Apr 11, 2022

Part of #7808 to be integrated with #7896

Who is this for?

Self-registered library members

What is it doing for them?

Giving them a page to fill out their names and accept terms once they've initiated the signup process (by entering an email/password in the Auth0 Universal login screen).

The call to /api/users/:user_id doesn't work at present. As discussed in standup, not sure whether it is a problem/security concern for this page to be live (either on stage or prod) in a state where it doesn't currently work while we connect it to the identity repo in order to do the updating of the user metadata. What are the options? I had thought of putting it behind a toggle (but if there were security concerns, that wouldn't solve them).

TODO
Work out what to send back to Auth0. This PR won't work because it attempts to call the updateUser method via the /api/users/:user_id route, but that would need to have a password sent along with it

image

@github-actions
Copy link

github-actions bot commented Apr 12, 2022

Size Change: +14.8 kB (+1%)

Total Size: 1.13 MB

Filename Size Change
catalogue/webapp/.next/static/chunks/504-********************.js 0 B -6.18 kB (removed) 🏆
catalogue/webapp/.next/static/chunks/585-********************.js 0 B -7.04 kB (removed) 🏆
catalogue/webapp/.next/static/chunks/63-********************.js 0 B -2.88 kB (removed) 🏆
catalogue/webapp/.next/static/chunks/pages/image-********************.js 3.31 kB +2.09 kB (+173%) 🆘
catalogue/webapp/.next/static/chunks/pages/images-********************.js 4.78 kB -805 B (-14%) 👏
content/webapp/.next/static/chunks/236-********************.js 0 B -3.13 kB (removed) 🏆
content/webapp/.next/static/chunks/356-********************.js 0 B -42.9 kB (removed) 🏆
identity/webapp/.next/static/chunks/242-********************.js 0 B -13.8 kB (removed) 🏆
catalogue/webapp/.next/static/chunks/916-********************.js 7.05 kB +7.05 kB (new file) 🆕
catalogue/webapp/.next/static/chunks/956-********************.js 4.88 kB +4.88 kB (new file) 🆕
catalogue/webapp/.next/static/chunks/997-********************.js 4.1 kB +4.1 kB (new file) 🆕
content/webapp/.next/static/chunks/426-********************.js 7.74 kB +7.74 kB (new file) 🆕
content/webapp/.next/static/chunks/60-********************.js 42.6 kB +42.6 kB (new file) 🆕
identity/webapp/.next/static/chunks/357-********************.js 10.7 kB +10.7 kB (new file) 🆕
identity/webapp/.next/static/chunks/442-********************.js 8.18 kB +8.18 kB (new file) 🆕
identity/webapp/.next/static/chunks/pages/registration-********************.js 4.57 kB +4.57 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
catalogue/webapp/.next/static/chunks/00a8a139.********************.js 54.3 kB 0 B
catalogue/webapp/.next/static/chunks/321-********************.js 19.2 kB 0 B
catalogue/webapp/.next/static/chunks/33.********************.js 1.84 kB 0 B
catalogue/webapp/.next/static/chunks/410-********************.js 12.6 kB -488 B (-4%)
catalogue/webapp/.next/static/chunks/735.********************.js 19.3 kB 0 B
catalogue/webapp/.next/static/chunks/813-********************.js 4.34 kB -16 B (0%)
catalogue/webapp/.next/static/chunks/814-********************.js 2.79 kB 0 B
catalogue/webapp/.next/static/chunks/819-********************.js 3.73 kB 0 B
catalogue/webapp/.next/static/chunks/907-********************.js 3.19 kB 0 B
catalogue/webapp/.next/static/chunks/framework-********************.js 42.6 kB 0 B
catalogue/webapp/.next/static/chunks/main-********************.js 23.6 kB 0 B
catalogue/webapp/.next/static/chunks/pages/_app-********************.js 129 kB +1 B (0%)
catalogue/webapp/.next/static/chunks/pages/_error-********************.js 319 B 0 B
catalogue/webapp/.next/static/chunks/pages/404-********************.js 261 B 0 B
catalogue/webapp/.next/static/chunks/pages/download-********************.js 6.98 kB 0 B
catalogue/webapp/.next/static/chunks/pages/item-********************.js 4.83 kB -253 B (-5%)
catalogue/webapp/.next/static/chunks/pages/work-********************.js 23.2 kB +447 B (+2%)
catalogue/webapp/.next/static/chunks/pages/works-********************.js 3.28 kB +4 B (0%)
catalogue/webapp/.next/static/chunks/polyfills-a40ef1678bae11e696dba45124eadd70.js 31 kB 0 B
catalogue/webapp/.next/static/chunks/webpack-********************.js 1.61 kB 0 B
content/webapp/.next/static/chunks/219-********************.js 5.24 kB 0 B
content/webapp/.next/static/chunks/291-********************.js 3.89 kB 0 B
content/webapp/.next/static/chunks/353-********************.js 994 B 0 B
content/webapp/.next/static/chunks/471-********************.js 4.8 kB 0 B
content/webapp/.next/static/chunks/594-********************.js 1.75 kB 0 B
content/webapp/.next/static/chunks/600-********************.js 5.01 kB 0 B
content/webapp/.next/static/chunks/735.********************.js 19.3 kB 0 B
content/webapp/.next/static/chunks/739-********************.js 4.06 kB 0 B
content/webapp/.next/static/chunks/754-********************.js 7.27 kB 0 B
content/webapp/.next/static/chunks/901.********************.js 1.44 kB 0 B
content/webapp/.next/static/chunks/framework-********************.js 42.6 kB 0 B
content/webapp/.next/static/chunks/main-********************.js 23.6 kB 0 B
content/webapp/.next/static/chunks/pages/_app-********************.js 133 kB +1 B (0%)
content/webapp/.next/static/chunks/pages/_error-********************.js 330 B 0 B
content/webapp/.next/static/chunks/pages/404-********************.js 259 B 0 B
content/webapp/.next/static/chunks/pages/article-********************.js 5.3 kB +1 B (0%)
content/webapp/.next/static/chunks/pages/article-series-********************.js 1.94 kB 0 B
content/webapp/.next/static/chunks/pages/articles-********************.js 2.58 kB 0 B
content/webapp/.next/static/chunks/pages/book-********************.js 1.74 kB 0 B
content/webapp/.next/static/chunks/pages/books-********************.js 2.58 kB 0 B
content/webapp/.next/static/chunks/pages/event-********************.js 6.82 kB 0 B
content/webapp/.next/static/chunks/pages/event-series-********************.js 1.93 kB +1 B (0%)
content/webapp/.next/static/chunks/pages/events-********************.js 4.95 kB 0 B
content/webapp/.next/static/chunks/pages/exhibition-********************.js 4.46 kB +2 B (0%)
content/webapp/.next/static/chunks/pages/exhibitions-********************.js 4.14 kB 0 B
content/webapp/.next/static/chunks/pages/guides-********************.js 4.46 kB 0 B
content/webapp/.next/static/chunks/pages/homepage-********************.js 4 kB 0 B
content/webapp/.next/static/chunks/pages/newsletter-********************.js 3.65 kB 0 B
content/webapp/.next/static/chunks/pages/page-********************.js 3.48 kB +2 B (0%)
content/webapp/.next/static/chunks/pages/season-********************.js 3.16 kB +2 B (0%)
content/webapp/.next/static/chunks/pages/stories-********************.js 1.3 kB 0 B
content/webapp/.next/static/chunks/pages/whats-on-********************.js 7.86 kB 0 B
content/webapp/.next/static/chunks/polyfills-a40ef1678bae11e696dba45124eadd70.js 31 kB 0 B
content/webapp/.next/static/chunks/webpack-********************.js 1.57 kB 0 B
identity/webapp/.next/static/chunks/735.********************.js 19.3 kB 0 B
identity/webapp/.next/static/chunks/framework-********************.js 42.4 kB 0 B
identity/webapp/.next/static/chunks/main-********************.js 23.6 kB 0 B
identity/webapp/.next/static/chunks/pages/_app-********************.js 155 kB +6 B (0%)
identity/webapp/.next/static/chunks/pages/_error-********************.js 193 B 0 B
identity/webapp/.next/static/chunks/pages/delete-requested-********************.js 1.47 kB 0 B
identity/webapp/.next/static/chunks/pages/error-********************.js 1.55 kB 0 B
identity/webapp/.next/static/chunks/pages/index-********************.js 11.5 kB -217 B (-2%)
identity/webapp/.next/static/chunks/pages/validated-********************.js 3.48 kB +146 B (+4%)
identity/webapp/.next/static/chunks/polyfills-a40ef1678bae11e696dba45124eadd70.js 31 kB 0 B
identity/webapp/.next/static/chunks/webpack-********************.js 1.54 kB 0 B

compressed-size-action

@davidpmccormick davidpmccormick marked this pull request as ready for review April 12, 2022 12:04
@davidpmccormick davidpmccormick requested a review from a team April 12, 2022 12:04
identity/webapp/package.json Outdated Show resolved Hide resolved
identity/webapp/pages/registration.tsx Outdated Show resolved Hide resolved
identity/webapp/pages/registration.tsx Outdated Show resolved Hide resolved
identity/webapp/src/utility/jwt-codec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jamieparkinson jamieparkinson left a comment

Choose a reason for hiding this comment

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

Coming along nicely, wonder if it's worth splitting this into a few PRs as it's turned into a (very valuable) spike in some senses

const newToken = generateNewToken(decodedToken, state, formData);

res.redirect(
308,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a 308 here? I think browsers will cache this very aggressively, which might cause issues

Copy link
Contributor Author

@davidpmccormick davidpmccormick Apr 25, 2022

Choose a reason for hiding this comment

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

http status codes aren't my strong suit, but I think you'd previously suggested a 301, and a 308 is equivalent, but as the result of a POST from what I read. But maybe I had the 301 wrong in the first place? Maybe I want 307 instead? Or more likely 302 since the method can (should) change from POST to GET?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, not sure why I said 301 lol 🙃 This is interesting - it's definitely not a permanent redirect, so looking at this it's not actually clear that there's anything which is a good fit. This is, I think, a good clue that we should tweak the approach...

  • We're making a POST to our endpoint with our form data (this is fine and good)

  • We want to Do Some Stuff with that data and then POST to the /continue endpoint of Auth0 (I think?) as per these docs

  • We are currently trying to make that POST by giving the client a redirect to it, but that seems hard. Looking into it further, it's explicitly disallowed by the spec!

    in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user

  • Solution: I think we should just make that request ourselves in the server-side code (ie with axios or whatever), and then redirect with a 302 to the account page (or an error page).

Copy link
Contributor

@melanierogan melanierogan Apr 25, 2022

Choose a reason for hiding this comment

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

I think I get what you mean, so line 21 is currently a redirect - we need that to be a post so we can use something like axios.post() then redirect to error/success page based on that

Comment on lines 6 to 13
const {
state,
redirectUri,
firstName,
lastName,
termsAndConditions,
sessionToken,
} = req.body;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be checking that these are populated as expected and returning a 400 if not


res.redirect(
308,
`${redirectUri}?state=${state}&session_token=${newToken}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to consider whether passing an arbitrary redirectUri here could be harmful - elsewhere (callback and login URLs) we have to provide a whitelist. Not sure whether that's required here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point – we wouldn't expect the redirectUri to change would we?

Copy link
Contributor

Choose a reason for hiding this comment

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

True, it's always going to be this /continue endpoint right? I think we should be able to construct that from the Auth0 config variables that we already have

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do as Jamie suggests and construct this from the Auth0 config variables

},
});

const RegistrationPage: NextPage<Props> = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this page probably needs to be split up into a few components

Comment on lines 32 to 40
| 'iat'
| 'iss'
| 'sub'
| 'exp'
| 'aud'
| 'state'
| 'https://wellcomecollection.org/terms_agreed'
| 'https://wellcomecollection.org/first_name'
| 'https://wellcomecollection.org/last_name'
Copy link
Contributor

Choose a reason for hiding this comment

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

Fun TS tip (not necessarily better than this, just worth knowing):

const jwtRequiredFields = [
  'iat',
  'iss',
  'sub',
  'exp',
  'aud',
  'state',
  'https://wellcomecollection.org/terms_agreed',
  'https://wellcomecollection.org/first_name',
  'https://wellcomecollection.org/last_name'
] as const;
type RegistrationJwtPayload = Pick<JwtPayload, typeof jwtRequiredFields[number]>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

neat – I prefer writing commas at the ends of lines to pipes and spaces at the beginning!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is the as const important? IDE not shouting at me if I take it off. I guess it must be otherwise TS would just thing jwtRequiredFields was an array of any strings

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?

@davidpmccormick davidpmccormick deleted the membership-form branch April 25, 2022 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants