-
I am experiencing an issue where the Code Snippet//server action function
export const createSwipeSource = authActionClient
.schema(NewSwipeSourceSchema)
.action(async ({ parsedInput, ctx }) => {
const newSwipeSource = {
...parsedInput,
userId: parsedInput.userId ?? ctx.userId,
};
const [insertedSwipeSource] = await db
.insert(swipeSources)
.values(newSwipeSource)
.returning();
return { success: true, data: insertedSwipeSource };
});
//use the server action function
const { execute, status, executeAsync, reset, isExecuting, result } = useAction(
createSwipeSource,
{
onExecute: ({ input }) => {
console.log("executing");
},
onSuccess: ({ data, input }) => {
console.log("success", data);
toast({
title: "Success",
description: "Swipe source created successfully!",
variant: "success",
});
},
onError: ({ error, input }) => {
console.log("error", error);
toast({
title: "Error",
description: "Failed to create swipe source. Please try again.",
variant: "destructive",
});
},
onSettled: ({ result, input }) => {
console.log("settled");
setOpen(false);
},
}
);
//safe action client and middleware
export const authActionClient = createSafeActionClient({
defaultValidationErrorsShape: "flattened",
}).use(async ({ next }) => {
const session = await auth();
const userId = session?.user?.id;
if (!userId) {
throw new Error("Session is not valid!");
}
return next({ ctx: { userId } });
}); Expected BehaviorThe Actual BehaviorThe I am using
Debugging Steps Taken
|
Beta Was this translation helpful? Give feedback.
Answered by
7codo
Sep 7, 2024
Replies: 1 comment 2 replies
-
Hi, can you please provide a link to a minimal reproduction of the issue? Thanks. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your response! I was able to solve the issue by adjusting the Next.js middleware configuration. Initially, I was setting the headers like this:
However, I realized the correct approach is:
This change resolved the problem.