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

Meteor.loginWithPassword should have a similar signature as Accounts.createUser #13069

Open
jamauro opened this issue Mar 21, 2024 · 5 comments
Labels
good first issue Good first issue or something that should is nice to do. Project:Accounts:Password

Comments

@jamauro
Copy link
Contributor

jamauro commented Mar 21, 2024

It feels kind of weird that Accounts.createUser and Meteor.loginWithPassword have different signatures. I propose that Meteor.loginWithPassword is updated so that you can do this:

Meteor.loginWithPassword({ email, password }, (error, result) => {...})

I suppose it should have backwards compatibility so people aren't forced to rewrite their existing code.

Thoughts?

@nachocodoner
Copy link
Member

I like your proposal. Feels clear to expect similar and consistent interfaces for functions that are alike. I particularly prefer the approach of passing parameters as objects, which enhances versatility and facilitates quick refactoring if needed.

@StorytellerCZ StorytellerCZ added Project:Accounts:Password good first issue Good first issue or something that should is nice to do. labels Mar 26, 2024
@abhinavtps
Copy link

Hi @jamauro

This is my first open source, can you please guide me?

I see that updating the function definition of loginWithPassword in https://github.com/meteor/meteor/blob/devel/packages/meteor/meteor.d.ts with an object would suffice like below

function loginWithPassword(
user: { username?: string; email?: string; id?: string } | string,
password: string,
callback?: (error?: global_Error | Meteor.Error | Meteor.TypedError, result?: any) => void
): void;

I think it should not break any existing functionality, is this the expected fix?

@jamauro
Copy link
Contributor Author

jamauro commented Mar 28, 2024

I suppose it should have backwards compatibility so people aren't forced to rewrite their existing code.

@nachocodoner any thoughts on whether it should be a breaking change or not? It would certainly be cleaner from a core code standpoint to make a breaking change but would require developers to make a small change in their code.

Also I think we'll want Meteor.passwordlessLoginWithTokenAnd2faCode to be updated similarly to Meteor.loginWithPassword as part of this issue.


Hey @abhinavtps, thanks for your willingness to jump on this one. Before diving into the solution, let's wait and see if the Meteor team thinks it's worth introducing a breaking change or not. The code will look quite a bit different depending on the answer to that question.

After we have a clearer picture of what's needed, the bulk of the work will need to happen here:

Meteor.loginWithPassword = (selector, password, callback) => {

and here:

Meteor.passwordlessLoginWithTokenAnd2faCode = (selector, token, code, callback) => {

The js doc and .d.ts for these functions will need to be updated as well.

It will also need tests added / updated here: https://github.com/meteor/meteor/blob/devel/packages/accounts-password/password_tests.js to ensure the new proposed way works as expected.

@nachocodoner
Copy link
Member

any thoughts on whether it should be a breaking change or not? It would certainly be cleaner from a core code standpoint to make a breaking change but would require developers to make a small change in their code.

I propose avoiding breaking changes by implementing it with polymorphism, supporting both parameter and object approaches. We'll provide a deprecation log for the parameter approach, warning users about the convention change, to be removed in a future release. What are your thoughts?

@jamauro
Copy link
Contributor Author

jamauro commented Apr 3, 2024

I like that approach.

@abhinavtps see Nacho’s comment above for the desired solution. If you have follow up questions, feel free to use this thread. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good first issue or something that should is nice to do. Project:Accounts:Password
Projects
None yet
Development

No branches or pull requests

4 participants