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

@W-16553557 Add passwordless login helpers #173

Merged
merged 5 commits into from
Sep 25, 2024

Conversation

jeremy-jung1
Copy link
Collaborator

@jeremy-jung1 jeremy-jung1 commented Sep 18, 2024

Adding login helpers in isomorphic for passwordless login

E2E Test:

  1. Go to https://runtime-admin-n18.mobify-storefront.com/
  2. Open Network tab, and put "passwordless" in the search bar
  3. Refresh. See a 200 response from passwordless/login.
  4. Go to https://webhook.site/#!/view/4cb9f313-a8e0-4066-bf2e-5087edf1bf66/5abe16c4-b112-4e12-90cd-8e91aea88598/1
  5. Click on the latest POST request, and copy the "token" field in the shown content of the request.
  6. Go back to the tab with the storefront. Scroll all the way down until you see a small submission form at the bottom left of the bottom of the window (should say "Enter text")
  7. Have the network tab open, and paste the "token" in the input field and press submit.
  8. See 200 response from 'passwordless/token`

@jeremy-jung1 jeremy-jung1 requested a review from a team as a code owner September 18, 2024 18:01
Comment on lines 101 to 102
grant_type: 'client_credentials',
hint: 'pwdless_login',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -8,6 +8,7 @@
// Doing so may lead to circular dependencies or duplicate exports (due to rollup mangling the types)
export * from './environment';
export * from './slasHelper';
export * from './passwordlessHelper';
Copy link

Choose a reason for hiding this comment

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

NIT: The passwordless login API's are part of SLAS right? And from the looks of it, the content of this file is somewhat small, is there a reason you didn't slap it in the slasHelpers, sounds like that is the right context for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but it was moved to its own file because adding these functions fails the 500 line rule for slasHelpers in linting

Copy link

Choose a reason for hiding this comment

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

Thats super lame, seems a little arbitrary.

It definitely seems like the SLAS passwordless helper should be located along with all the other SLAS helpers. Can you propose an alternative (non-breaking) solution here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that it's pretty arbitrary, when the line limit was implemented (3 years ago) I don't think the team originally envisioned a helper file growing to this size. I think it'd be ok to update the line limit or ignore it for this file:

Ignore: /* eslint-disable max-lines */
Update max lines:

Copy link
Collaborator Author

@jeremy-jung1 jeremy-jung1 Sep 23, 2024

Choose a reason for hiding this comment

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

I'll override the max-lines for this file to make it as flexible as possible for new helpers as part of this epic

)}`;
const tokenBody = {
user_id: parameters.userid,
mode: parameters.mode,
Copy link

Choose a reason for hiding this comment

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

NIT: It doesn't look like we have have a pattern for throwing when required params are not included, so I don't expect you to add it now because I like consistency more. But I'll take note on that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It also seems like typescript checks for the existence of these params that are directly required. But when it's parameters within an object like ShopperLogin, typescript doesn't automatically give an error that expected arguments don't exist

Copy link

Choose a reason for hiding this comment

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

We shouldn't reply on TypeScript types for things like that because this lib is compiled into JS and it can be used by a project that isn't TS. Typescript won't bake in any kind of parameter checking so there is the possibility that you this code would make a server request that would for sure fail if that param is required.

But again, no need to change that now, it doesn't seem like it's a pattern that we have, and we should probably fix that in another PR in one big swoop.

siteId: string;
}>,
credentials: {
clientSecret: string;
Copy link

Choose a reason for hiding this comment

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

You might want to throw if this information is not provided as we are doing here. This comment also applies to the getPasswordLessAccessToken function implementation below.

Copy link
Contributor

@yunakim714 yunakim714 left a comment

Choose a reason for hiding this comment

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

E2e tests working as expected and the helpers look good to me!

@jeremy-jung1 jeremy-jung1 merged commit b587cbf into main Sep 25, 2024
8 checks passed
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.

4 participants