T
TanStack2w ago
wise-white

Resend email not working with TanStack Start

I want to use Resend and react email to send email verification when I sign up using better auth, but I can't make it work in tanstack start. Neither Server Functions nor Server Routes were able to send email.
3 Replies
vicious-gold
vicious-gold2w ago
do you get any error? as it stands, your issue wont be solvable without a lot more context
wise-white
wise-whiteOP2w ago
I can't use the react prop (commented-out code), I have this error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app but the html prop works, VerifyEmail is using react email components so, how do I render a react component in a server function?
No description
sunny-green
sunny-green2w ago
Have you tried converting to html and passing html to Resend instead? Assuming you're using react.email, so something like this:
import { render } from '@react-email/render'

// inside createServerFn
const html = await render(VerifyEmail({ username="..." verifyUrl="..." }));

const { data } = await resend.emails.send({
from: "email@example.com",
to: "email@example.com",
subject: "Hello!",
html
});
import { render } from '@react-email/render'

// inside createServerFn
const html = await render(VerifyEmail({ username="..." verifyUrl="..." }));

const { data } = await resend.emails.send({
from: "email@example.com",
to: "email@example.com",
subject: "Hello!",
html
});

Did you find this page helpful?