-
-
Notifications
You must be signed in to change notification settings - Fork 141
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: magic-link; password-free login #1150
Conversation
🦋 Changeset detectedLatest commit: 62997f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Thank you very much for the pr, this will be a great addition that a lot of people requested!
As a general note, what do you think about renaming @accounts/token
to @accounts/magic-link
? The name is pretty standard for these kinds of authentication services, so it will be clear what this package is doing.
Regarding the logic, the implementation sounds good, I didn't do a deep review for this one but left a few small comments for now.
I was not able to compile the packages locally, graphql-client is throwing an error.
Security questions:
- when requesting 2 emails, should both be active or just the last one sent? So when I ask for a new email it invalidates all the previous tokens, only the last email link is working.
- after a successful login all the tokens should be invalidated
More comments: documentation and examples are still missing for this, is this something you would be up to do? |
Yes, but if possible in a later PR. |
Sounds good!
Both of these makes sense, but maybe they could/should be covered by options? Or tied to the reason, such that login tokens explicitly added through addLoginToken could be managed by other means. |
0c97bcc
to
92d1419
Compare
Codecov Report
@@ Coverage Diff @@
## master #1150 +/- ##
==========================================
- Coverage 95.49% 95.39% -0.11%
==========================================
Files 93 106 +13
Lines 2152 2344 +192
Branches 402 458 +56
==========================================
+ Hits 2055 2236 +181
- Misses 95 105 +10
- Partials 2 3 +1
Continue to review full report at Codecov.
|
Fix issues from PR
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.
-
can you provide an example of the user creation? My understanding is that a password would be required in the current state? I might be missing something obvious tho :D
-
I guess you deleted the
yarn.lock
file and it was regenerated from scratch, this is creating some issues, could you please revert the change you made and update the one from master instead of recreating it?
packages/types/src/types/services/magic-link/database-interface.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Léo Pradel <pradel.leo@gmail.com>
Co-authored-by: Léo Pradel <pradel.leo@gmail.com>
Co-authored-by: Léo Pradel <pradel.leo@gmail.com>
Remove unused errors
Clean up related tests.
regarding this, it's a bit weird that you have to add the password package too, this means that all the mutations (or routes via REST) will be exposed and user creation via password will be allowed. |
Well, with the last cleanup I think that should work. The example was mostly like that since I do use the password module for user creation (and also for alternative login method). I haven't tried without though. |
Okay, would be great to have the example so we are sure it's working that way. Will make it easier for users to get started with magic-link! |
you guys are gods |
Amazing work @larsivi thank you so much for this! |
Everything is published on npm, would be cool to get some documentation for other users! |
Thank you! I'll look at writing some docs over the next few weeks. |
This is an addon service to password and adds the ability to authenticate via a token. The token can be sent to you via email using the requestLoginToken endpoint, or by other means server side by generating a token and adding it using addLoginToken. Users can now be found with this token, using findUserByLoginToken.
Default expiry is 15 minutes.
Three new packages are added, magic-link and mongo-magic-link and client-magic-link.
There is a logical dependency on package that handles users (typically password which in any case is a good companion module), but it is not hard if you have a different one providing the same.
Example of use (serverside, accompanied by password):
Example of use clientside (using GraphQL):