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

Pass options into server-side log-in lifecycle hooks #13085

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

nazrhyn
Copy link

@nazrhyn nazrhyn commented Apr 8, 2024

Details

Currently, any options provided by the log-in handler that services a log-in attempt are not passed to the server-side Accounts.onLogin and .onLoginFailure lifecycle hooks as part of the attempt. We use these lifecycle hooks for various integrations and application features, and it would be nice to be able to transport custom information between those two locations. Currently, we're doing something very unpleasant to bridge that gap.

This change modifies Accounts._attemptLogin, following the pattern for error and user, attaching options to the attempt object being built there. This is really the only material change, but I've also done some more work.

Related to this change is the following PR where a co-worker of mine made a similar change for the client-side userCallback of Accounts.callLoginMethod. My change brings parity on the server-side, making sure options are passed everywhere they might be useful.

As a gesture of good will 😇, I have also written a small suite of tests that covers:

  1. Server-side log-in in several permutations
    • Checks the Accounts.validateLoginAttempt hook
    • Checks the Accounts.onLogin hook
    • Checks the Accounts.onLoginFailure hook
  2. Client-side successful log-in
    (These tests essentially cover my co-worker's PR changes from before.)
    • Checks the validateResult callback
    • Checks the userCallback callback

Potentially Contentious Things

  • I created new modules to house these tests, as I knew I would want some helpers and I didn't necessarily want to just jam all of this stuff into the existing modules. Please let me know if you'd like changes to how this is organized.
  • I see you have a Prettier config, but when I ran it, it produced an output that seems to indicate that it is not often being run, based on comparisons with existing code. Please let me know if you want me to run it, even if it produces inconsistent output.
  • You didn't have any concept of a mock function, as far as I could see, and I wanted to use something like that to easily record calls without having to write that functionality over and over. I created a MockFunction class and added it to test-helpers. I considered it to be an expedient in writing these tests, but if it's too new or out of line with what you want in your test suite, please let me know.
  • I think I understood what you were doing with accounts_tests_setup.js, but please let me know if I did that wrong.
  • As far as I could see, you didn't have any existing tests that directly test the server-side Accounts.registerLoginHandler function with a test-only handler. I wanted to write tests that were focused in scope, and so that's how I went about it, rather than relying on existing handlers that might've been added in other packages.

@CLAassistant
Copy link

CLAassistant commented Apr 8, 2024

CLA assistant check
All committers have signed the CLA.

Comment on lines 26 to +45
api.export([
'pollUntil', 'try_all_permutations',
'SeededRandom', 'clickElement', 'blurElement',
'focusElement', 'simulateEvent', 'getStyleProperty', 'canonicalizeHtml',
'renderToDiv', 'clickIt',
'withCallbackLogger', 'testAsyncMulti',
'simplePoll', 'runAndThrowIfNeeded',
'makeTestConnection', 'DomUtils']);
'blurElement',
'canonicalizeHtml',
'clickElement',
'clickIt',
'DomUtils',
'focusElement',
'getStyleProperty',
'makeTestConnection',
'MockFunction',
'pollUntil',
'renderToDiv',
'runAndThrowIfNeeded',
'SeededRandom',
'simplePoll',
'simulateEvent',
'testAsyncMulti',
'try_all_permutations',
'withCallbackLogger',
]);
Copy link
Author

Choose a reason for hiding this comment

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

I completely understand if you want me to revert this and just add the single thing to make this diff better. I just ... really wanted to make this cleaner for the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with this.

@nazrhyn nazrhyn marked this pull request as ready for review April 8, 2024 22:40
@nazrhyn
Copy link
Author

nazrhyn commented Apr 8, 2024

Aside: running the test suite locally to verify it's all passing, it finished like this:

image

"All tests pass!" but "Passed 1598 of 1599" 🤔

EDIT: Oh hmm, maybe this is significant. This is what happened in CI:
https://app.travis-ci.com/github/meteor/meteor/builds/269881541#L5522

Tests complete with 1 failures
Tests complete with 1598 passes
S: tinytest - livedata server - onMessage hook failed: {"groupPath":["tinytest","livedata server"],"test":"onMessage hook","events":[{"sequence":2829,"type":"fail","details":{"type":"string_equal","expected":"livedata_server_test_inner","actual":"tinytest/getCurrentRunningTestName"}}],"server":true}

I'm not seeing what that 1 failure is, though... hopefully not related to my change.

* Provides server-side parity with the work started in meteor#11913
* Attaches any `options` provided in the result of the log-in handler to the `attempt`
* Adds a small suite of tests covering client-side and server-side places where `options` is expected to be available
@denihs
Copy link
Contributor

denihs commented May 20, 2024

Hey @nazrhyn, do you need this for Meteor 2? It might take a while before we have another version 2 release. But we could include this in the next 3.0-rc

@nazrhyn
Copy link
Author

nazrhyn commented May 20, 2024

@denihs Thanks for the follow up!

We have a local fork that includes this change in our current version, so there's no urgency on our side. We just wanted to contribute this back in case the Meteor team liked it.

Copy link
Collaborator

@StorytellerCZ StorytellerCZ left a comment

Choose a reason for hiding this comment

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

LGTM, the only thing is that I would probably target this on the 3.x branch.

@nazrhyn
Copy link
Author

nazrhyn commented May 20, 2024

Would you like me to rebase it or is that something y'all will do? I don't mind, just need the exact branch name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants