Server Action Form Issues
Answered
ItsANoBrainer posted this in #help-forum
I am following the dashboard-app tutorial and am currently at:
https://nextjs.org/learn/dashboard-app/mutating-data#5-inserting-the-data-into-your-database
I am at the point where I am creating a Server Action that is called when the form is submitted. This Action adds content to the database. My issue is that on form submission, I am getting:
Even though my
I have console logged the env variables outside the action function and can see them properly, but they dont see them inside the server action, I assume for the above reason.
What am I doing wrong? Am I missing something? I'm fairly confident I have followed the tutorial properly, and I do not know enough to further debug my issue. Thank you!
My code can be found here: https://github.com/ItsANoBrainer/nextjs-dashboard
The site for testing for replication: https://nextjs-dashboard-two-zeta-42.vercel.app/dashboard/invoices/create
Action: https://github.com/ItsANoBrainer/nextjs-dashboard/blob/master/app/lib/actions.ts#L18-L37
Form that Calls Action: https://github.com/ItsANoBrainer/nextjs-dashboard/blob/master/app/ui/invoices/create-form.tsx#L16
https://nextjs.org/learn/dashboard-app/mutating-data#5-inserting-the-data-into-your-database
I am at the point where I am creating a Server Action that is called when the form is submitted. This Action adds content to the database. My issue is that on form submission, I am getting:
VercelPostgresError: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.Even though my
action.ts file is using use server, it seems like the Action is being ran client side, as the action is being called in a form that has use client. This is causing my sql command to not see the environment variables for hitting the database. (Also running console logging in my action is logging on the client not the server as well).I have console logged the env variables outside the action function and can see them properly, but they dont see them inside the server action, I assume for the above reason.
What am I doing wrong? Am I missing something? I'm fairly confident I have followed the tutorial properly, and I do not know enough to further debug my issue. Thank you!
My code can be found here: https://github.com/ItsANoBrainer/nextjs-dashboard
The site for testing for replication: https://nextjs-dashboard-two-zeta-42.vercel.app/dashboard/invoices/create
Action: https://github.com/ItsANoBrainer/nextjs-dashboard/blob/master/app/lib/actions.ts#L18-L37
Form that Calls Action: https://github.com/ItsANoBrainer/nextjs-dashboard/blob/master/app/ui/invoices/create-form.tsx#L16
Answered by ItsANoBrainer
I accidently used backticks instead of single quotes for
use server. Fixed by using using single quotes properly, which actually registered the component as server side, as it wasn't beforehand.1 Reply
I accidently used backticks instead of single quotes for
use server. Fixed by using using single quotes properly, which actually registered the component as server side, as it wasn't beforehand.Answer