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

Add tokenGenerator to Email provider config #537

Closed
firede opened this issue Aug 3, 2020 · 4 comments
Closed

Add tokenGenerator to Email provider config #537

firede opened this issue Aug 3, 2020 · 4 comments
Labels
enhancement New feature or request stale Did not receive any activity for 60 days

Comments

@firede
Copy link
Contributor

firede commented Aug 3, 2020

Please stick to one distinct feature request per issue where possible and raise additional feature quests as separate issues. Try to avoid adding feature requests to existing issues in the comments of issues raised by other users.

Summary of proposed feature

Add tokenGenerator to Email provider config. example:

function randomMemorableToken(): string { /* ... */ }
// => "bacca-cavort-west-volley"

providers: [
  Providers.Email({
    tokenGenerator: randomMemorableToken
    server: {
      // ...
    },
  }),
],

Purpose of proposed feature

Customize notion style email:

Detail about proposed feature

// Generate token
const token = randomBytes(32).toString('hex')

const token = provider.tokenGenerator ? provider.tokenGenerator() : randomBytes(32).toString('hex') 

Potential problems
Usually need to be used with sendVerificationRequest.

Describe any alternatives you've considered
A clear and concise description of any alternative options you've considered.

Additional context
Any other context, screenshots, etc.

Please indicate if you are willing and able to help implement the proposed feature.
Yes! if the idea is accepted.

@firede firede added the enhancement New feature or request label Aug 3, 2020
@iaincollins
Copy link
Member

@firede Thanks for the submission. This is a great idea!

I don't know what we should call the function - maybe something like verificationToken() or generateVerificationToken() or createVerificationToken() - but I would be very happy to support and test this and to collaborate on the implementation.

I can see how, if we implemented this, it would be easy to extend later (e.g. to support things like 2FA input, SMS, etc) which is something a few folks have asked about.

In the immediate term, this really nicely solves the problem of people signing in to a browser on a device that does not configured to receive email at the email address they are using (e.g. by checking their phone and typing in the code in the browser on whatever device they are using).

Regarding implementation, the verification URLs already have the Provider ID in the URL (e.g. in the provider=email query string below is actually the provider.id value:
https://next-auth-example.now.sh/api/auth/verify-request?provider=email&type=email

With that in mind it would be very easy to update the verification page to handle displaying an input box if an option (e.g. provider.showVerificationTokenInput: true) is set on the provider. We could do something similar in the email provider template that also changes how it appears depending on if the option to display the verification token is enabled or not.

I'm very happy to help with aspect as needed.

@firede
Copy link
Contributor Author

firede commented Aug 4, 2020

@iaincollins Thanks for the comments.

maybe something like verificationToken() or generateVerificationToken() or createVerificationToken()

I voted for generateVerificationToken, the style is consistent with sendVerificationRequest.

With that in mind it would be very easy to update the verification page to handle displaying an input box if an option (e.g. provider.showVerificationTokenInput: true) is set on the provider.

Another option I recommend to use showVerificationToken, which makes sense in both the verification email and the verification page.

I will try to create a PR for this.

@stale
Copy link

stale bot commented Dec 5, 2020

Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep ot open. Thanks!

@stale stale bot added the wontfix This will not be worked on label Dec 5, 2020
@balazsorban44 balazsorban44 added stale Did not receive any activity for 60 days and removed wontfix This will not be worked on labels Dec 5, 2020
@stale
Copy link

stale bot commented Dec 12, 2020

Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale Did not receive any activity for 60 days
Projects
None yet
Development

No branches or pull requests

3 participants