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

Expose id and name for EmailProvider config #8941

Closed
wants to merge 1 commit into from

Conversation

basememara
Copy link

Allow multiple EmailProvider to be configured that vary by id.

☕️ Reasoning

In v4.22.1 and before, it was allowed to provide id and name to the email provider. This enabled multiple email providers to be declared and sign-in to conditionally target which email provider to use:

const authOptions = {
    ...,
    providers: [
      GoogleProvider({...}),
      EmailProvider({
        server: smtp1,
        sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
      }),
      EmailProvider({
        id: 'invite-member',
        name: 'Invite Member',
        server: smtp2,
        maxAge: 3 * 24 * 60 * 60,
        sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
      })
    ],
    ...
} satisfies AuthOptions

// elsewhere

await signIn('email', {
  callbackUrl: `${window.location.origin}/profile`,
  email
});

// or

await signIn('invite-member', {
  callbackUrl: `${window.location.origin}/auth/new-invite`,
  email
});

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

Fixes: #8125

📌 Resources

In v4.22.1 and before, it was allowed to provide `id` and `name` to the email provider. This enabled multiple email providers to be declared and sign-in to conditionally target which email provider to use:

```ts
const authOptions = {
    ...,
    providers: [
      GoogleProvider({...}),
      EmailProvider({
        server: smtp1,
        sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
      }),
      EmailProvider({
        id: 'invite-member',
        name: 'Invite Member',
        server: smtp2,
        maxAge: 3 * 24 * 60 * 60,
        sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
      })
    ],
    ...
} satisfies AuthOptions

// elsewhere

await signIn('email', {
  callbackUrl: `${window.location.origin}/profile`,
  email
});

// or

await signIn('invite-member', {
  callbackUrl: `${window.location.origin}/auth/new-invite`,
  email
});
```
@vercel
Copy link

vercel bot commented Oct 25, 2023

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

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 7:46am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Oct 25, 2023 7:46am

@vercel
Copy link

vercel bot commented Oct 25, 2023

@basememara is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@balazsorban44
Copy link
Member

superseded by #9753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core` providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP-based email provider: type "email" is not assignable to type "oauth" | "credentials"
2 participants