Next.js Discord

Discord Forum

Server actions + next-safe-action

Unanswered
Silver posted this in #help-forum
Open in Discord
SilverOP
Hey guys I'm getting a 404 not found on my server actions now and I'm not sure why

14 Replies

Can you share screenshot
or any relevant errors?
SilverOP
Getting this in my production deployment. It happens on vercel but not locally
I think it can't find the route for the server action
Can you share your server action code?
SilverOP
Sure thing, all of the server actions are broken

Here's a simple one
"use server";

import { supabase } from "@/lib/supabase";
import { action } from "@/src/actions/safe-action";
import { registerRaffleSchema } from "@/src/actions/schema";

export const registerRaffleAction = action(
  registerRaffleSchema,
  async ({ address, raffleName, signature }) => {
    // Check if address is already registered
    const { data } = await supabase
      .from("raffles")
      .select("*")
      .eq("address", address.toLowerCase())
      .eq("raffle_name", raffleName)
      .single();

    if (data) {
      throw new Error("Address already registered");
    }

    // Enter user into raffle by updating signature
    const { data: raffleData } = await supabase
      .from("raffle_submissions")
      .update({ signature })
      .eq("address", address.toLowerCase())
      .eq("raffle_name", raffleName)
      .throwOnError();

    return {
      success: true,
    };
  },
);


import { createSafeActionClient } from "next-safe-action";

export const action = createSafeActionClient({
  handleReturnedServerError: (e) => {
    console.log("handleReturnedServerError", e);
    if (e instanceof Error) {
      return e.message;
    }

    return "Oh no, something went wrong!";
  },
});
can you try running npm run build && npm start locally and see if you get any error?
Have you added environment variables to vercel?
@Anay-208 Have you added environment variables to vercel?
SilverOP
Like recently? I do have env vars in vercel
can you create a [min repro repo](https://nextjs-faq.com/minimal-reproduction-repository)?
SilverOP
Finding out it's a vercel issue I'm thinking