-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have it in our docs (https://docs.id.gov.sg/integrations-with-sgid/typescript-javascript/express-with-single-page-app-frontend#step-5-test-it-out) but let me add it here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in ca6c50a
There was a problem hiding this 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! 🌮
examples/express/index.ts
Outdated
// Exchange the authorization code and code verifier for the access token | ||
const { accessToken, sub } = await sgid.callback({ | ||
code: authCode, | ||
nonce: session.nonce, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this 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
examples/express/index.ts
Outdated
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 |
There was a problem hiding this comment.
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 Map
s instead?
There was a problem hiding this comment.
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
This is a rejig of #43 with a few major changes:
sgid-client
v2.0.0, which uses PKCE by default