Next.js Discord

Discord Forum

Server Action not being called

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
Wondering if anybody can help me out here, starting to get really annoyed with this. I have the following code for when a user signs up to my application:

sign-up.tsx
const onSubmit = async (data: SignupSchema) =>
startTransition(async () => {
try {
const result = await signUp.email({
email: data.email,
password: data.password,
name: ${data.firstName} ${data.lastName},
});

console.log('Sending Email');
await sendWelcomeEmailAction(data.email, data.firstName);
console.log('Email Sent');
toast.success('Account created successfully!');
router.push('/');
} catch (error) {
console.error('Signup error:', error);
}
});

actions.ts
'use server'

export const sendWelcomeEmailAction = async (email: string, firstName: string) => {
console.log('Attempting to send email');
return sendEmail(
email,
'Welcome to the app',
WelcomeEmail({
firstName,
}),
);
};

On the client I'm getting the logs that the Email was sent. But on the server the sendWelcomeEmailAction function never runs, the log isn't even printed. Where could I be going wrong or whats going on?

Version - 15.4.0-canary.34

5 Replies

Dutch
is it working outside of transition block
Polar bearOP
Nope, doesn't look like it hits it at all, no network request being attempted either
Dutch
maybe here is null or undef somehow await sendWelcomeEmailAction(data.email?, data.firstName?); can you do console.log("data", data) before this line
also you can try it with debugger; before that line
Polar bearOP
Yeah data has values, the account get's created fine etc. Just seems to completely bypass the server action. I'll try the debugger here and see.