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

chore(docs): new guide for sending email via http api #6555

Merged
merged 19 commits into from
Mar 5, 2023

Conversation

ndom91
Copy link
Member

@ndom91 ndom91 commented Jan 29, 2023

NOTE:

  • It's a good idea to open an issue first to discuss potential changes.
  • Please make sure that you are NOT opening a PR to fix a potential security vulnerability. Instead, please follow the Security guidelines to disclose the issue to us confidentially.

☕️ Reasoning

  • Added new guide (/guides/providers/email-http) for sending Emails (Magic Link verification) via HTTP email APIs, like those from cloud email service providers like SendGrid, Postmark, AWS SES, etc.
  • Q: Should I open another PR for "back-porting" and merging this guide into v4 docs?

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

Please scout and link issues that might be solved by this PR.

Fixes: INSERT_ISSUE_LINK_HERE

📌 Resources

@ndom91 ndom91 requested a review from ubbe-xyz as a code owner January 29, 2023 18:15
@vercel
Copy link

vercel bot commented Jan 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
auth-docs ❌ Failed (Inspect) Mar 5, 2023 at 3:32PM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
next-auth-docs ⬜️ Ignored (Inspect) Mar 5, 2023 at 3:32PM (UTC)


First, clone and setup a basic Auth.js project like the the one [provided in our example repo](https://github.com/nextauthjs/next-auth-example.git). I won't go into the details of setting up your project for Auth.js's [Email provider](https://next-auth.js.org/providers/email), but you will need to make at least the following modifications to the example repository, or any other project you're adding this support to, including:

- Install `nodemailer` as a dependency. The email provider also requires the use of a database adapter for Auth.js.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Install `nodemailer` as a dependency. The email provider also requires the use of a database adapter for Auth.js.

the point of this guide is to not need nodemailer

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, but you need it for the Email provider atm. It'll complain if you don't install it. I guess we can modify that in core.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the text actually since its a default dependency in the example-repo as well.

Copy link
Member

Choose a reason for hiding this comment

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

It'll complain if you don't install it

Right, because we have the import at the top of the module... 🤦 Then I would not use EmailProvider at all. The whole point of this tutorial is to get rid of nodemailer, it feels weird to recommend installing it, and it's also quite big.

Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

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

General feedback:

Essentially, an HTTP-based E-mail provider should only need a single sendVerificationRequest method, and no other config. I'll leave it up to you, but we might not even need the EmailProvider import, just do:

...
{
  type: "email",
  id: "sendgrid",
  async sendVerificationRequest() {
    ...
  }
}
...

Should mention that to sign the user in, you could call signIn("sendgrid", { email: "user@example.com" }) in the client. (Or id is email if you decide to keep the EmailProvider wrapper)

ndom91 and others added 2 commits January 30, 2023 09:59
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
@ndom91 ndom91 force-pushed the ndom91/docs-guide-http-api-email-sending branch from 975d43f to 30eac91 Compare January 30, 2023 09:02
@ndom91
Copy link
Member Author

ndom91 commented Jan 30, 2023

General feedback:

Essentially, an HTTP-based E-mail provider should only need a single sendVerificationRequest method, and no other config. I'll leave it up to you, but we might not even need the EmailProvider import, just do:

...
{
  type: "email",
  id: "sendgrid",
  async sendVerificationRequest() {
    ...
  }
}
...

Should mention that to sign the user in, you could call signIn("sendgrid", { email: "user@example.com" }) in the client. (Or id is email if you decide to keep the EmailProvider wrapper)

Yeah so first of all, good suggestions all the way through, committed almost all of them.

Wasn't sure about the NextAuth.js / Auth.js thing since this is giong in the main docs atm but the package is still next-auth (imagine how confusing it is for our users atm 😅).

I'll go over it again with the text style updates and add the HTML email as well. I actually implemented this in that briefkasten app of mine while I wrote this yesterday to make sure it worked and since I was still sending emails via my own gmail account SMTP there previously haha. So I used our html wrapper, works just fine. Can copy that over to the guide too 👍

Regarding the EmailProvider wrapper or just a custom provider like that ^^, wouldn't we be missing out on the verification request db creation? Or does that happen in core if the provider uses a sendVerificationRequest method? I think we should keep it more straight forward and just use the EmailProvider (without the nodemailer hard requirement I mentioned above), what do you think? Otherwise, yeah its just the EmailProvider({ sendVerificationRequest }) 👍

@ndom91
Copy link
Member Author

ndom91 commented Jan 30, 2023

Changed to we and mentioend our html function adn the text/plain/text/html body type thing 👍

@balazsorban44
Copy link
Member

EmailProvider is not necessary, the way we know it's an email provider is through the type: "email" property. 😉 See #6555 (comment)

@ndom91
Copy link
Member Author

ndom91 commented Jan 31, 2023

EmailProvider is not necessary, the way we know it's an email provider is through the type: "email" property. 😉 See #6555 (comment)

Okay great, will remove it then and do the custom provider route you mentioned to avoid nodemailer as well 👍

@ndom91
Copy link
Member Author

ndom91 commented Jan 31, 2023

@balazsorban44 alright, should be more or less ready to go 👍

@balazsorban44
Copy link
Member

This was not addressed: #6555 (comment)

@ndom91
Copy link
Member Author

ndom91 commented Feb 2, 2023

This was not addressed: #6555 (comment)

You mean removing the nodemaiker point? That should definitely be gone and I changed it to a custom provider so it doesn't complain anymore

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.

2 participants