Next.js Discord

Discord Forum

Problem with Next-Auth email provider and nodemailer

Unanswered
Tibo posted this in #help-forum
Open in Discord
I'm trying to set up an email provider with Next-Auth and Resend but i'm getting this error: Module not found: Can't resolve 'fs'.
Here's my Next-Auth setup for the provider:
EmailProvider({
      server: {
        host: process.env.EMAIL_SERVER_HOST,
        port: process.env.EMAIL_SERVER_PORT,
        auth: {
          user: process.env.EMAIL_SERVER_USER,
          pass: process.env.EMAIL_SERVER_PASSWORD,
        },
      },
      from: process.env.EMAIL_FROM,
    }),

And here's my server actions that should send the email:
'use server';

import { signIn } from 'next-auth/react';

import { successToast } from '@/components';
import 'server-only';

type EmailSignInData = {
  email: string;
};

export async function emailSignIn(formData: FormData) {
  const data = Object.fromEntries(formData) as EmailSignInData;
  await signIn('email', data);
  successToast(`Link sent to ${data.email}`);
}

I'm getting this error no matter if nodemailer is installed or not.
This error disappear when I comment the part in the Next-Auth setup.
I don't understand what is triggering this error as I'm following Next-Auth guide.

12 Replies

Velvet ant
What is the next auth version ? And also signIn function should come from where you declare your providers
@Velvet ant I'm using the version 4.24.7. In the docs it says that I have to import signIn from next-auth/reactand I already have the Google provider with a signInfrom next-auth/react and it works perfectly.
Velvet ant
Yes my bad it’s in v5 for signIn function
Velvet ant
still weird that you can use the signIn from 'next-auth/react' in a server action since its only for client side.
@Tibo
Velvet ant
it seems that something that should be on server is done client side, that why the error is here.
I would go with next-auth v5 tbh
I just checked and the signIn for the Google provider is called in a client component so I'll have to move the signIn from the actions to a client component. Thanks for pointing this problem out
I'd like to make it work with v4 because v5 is still in beta and the docs aren't really good and complete
Velvet ant
sure its in beta but even next js tutorial use the v5 and it fits better with server side I guess
https://nextjs.org/learn/dashboard-app/adding-authentication
seems complete to me 🙂
I'll try to move the signIn function in a client component and if it doesn't work I'll migrate to v5