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

feat: express example #50

Merged
merged 31 commits into from
May 23, 2023
Merged

feat: express example #50

merged 31 commits into from
May 23, 2023

Conversation

kwajiehao
Copy link
Contributor

This is a rejig of #43 with a few major changes:

  1. Frontend is no longer pulled and delivered statically, but run separately as a SPA (see https://github.com/opengovsg/sgid-demo-frontend-spa)
  2. As part of that, configure CORS to work with the SPA
  3. Update documentation
  4. Update to use sgid-client v2.0.0, which uses PKCE by default

mantariksh and others added 24 commits May 5, 2023 12:00
This commit deletes the fetching of the static frontend because
we want to shift to a model of hosting the frontend separately from
the backend. The reason for this is that having a backend server
+ separate frontend SPA is a more common mode of development and
deployment
This commit makes a few changes:
1. Install CORS
2. Configure CORS to work with the frontend SPA
3. Remove code that serves the static frontend

This is in accordance with what we discussed, since a backend +
frontend SPA development pattern is expected to be most common.
@kwajiehao kwajiehao requested a review from raynerljm May 17, 2023 08:33
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to add instructions here on how to run the frontend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in ca6c50a

Copy link
Contributor

@raynerljm raynerljm left a comment

Choose a reason for hiding this comment

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

mostly looks good! just some small nits - thanks for fixing this up! 🌮

.eslintignore Outdated Show resolved Hide resolved
examples/express/README.md Outdated Show resolved Hide resolved
examples/express/README.md Outdated Show resolved Hide resolved
examples/express/README.md Show resolved Hide resolved
// Exchange the authorization code and code verifier for the access token
const { accessToken, sub } = await sgid.callback({
code: authCode,
nonce: session.nonce,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we destructure the nonce and codeVerifier from the session? because in/userinfo the values are being extracted from the session before being passed to userinfo (might also make passing the params a bit neater)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed it in the callback code in aca2c32

i didn't fix it for userinfo because you can't destructure an undefined item (session is possibly undefined). We could check for whether session is defined first, but since we also need to check for access token and sub, it doesn't really make sense to destructure there

examples/express/index.ts Outdated Show resolved Hide resolved
examples/express/index.ts Show resolved Hide resolved
@kwajiehao kwajiehao requested a review from raynerljm May 23, 2023 08:01
Copy link
Contributor

@raynerljm raynerljm left a comment

Choose a reason for hiding this comment

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

just 2 minor suggestions! other than that LGTM :D

apiRouter.get('/logout', async (_req, res) => {
apiRouter.get('/logout', async (req, res) => {
const sessionId = String(req.cookies[SESSION_COOKIE_NAME])
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if we have to disable this rule, should we consider either turning off the rule or using javascript Maps instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since Map is not fully supported by all browsers, I chose to turn off the rule instead. fixed in beef837

examples/express/package.json Outdated Show resolved Hide resolved
@kwajiehao kwajiehao merged commit baf5260 into develop May 23, 2023
@kwajiehao kwajiehao deleted the feat/examples-express-updated branch May 23, 2023 08:21
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