Server Action Fetch never executes
Answered
Beveren posted this in #help-forum
BeverenOP
Hi, ive got this server action.
the await fetch never seems to execute.
The console log before the try works, but then its dead. No request reaches my backend, no further console.log will be printed.
The action returns a generic error:
My Code:
the await fetch never seems to execute.
The console log before the try works, but then its dead. No request reaches my backend, no further console.log will be printed.
The action returns a generic error:
0:["$@1",["development",null]]
1:{"message":"Error","response":{}}My Code:
interface State {
message?: string,
path?: string,
}
export async function ClanTagAction(prevState: State, formData: FormData) {
const sessionToken = cookies().get('next-auth.session-token')?.value
if (!sessionToken || sessionToken.length === 0) return prevState;
console.log("THIS PRINTS");
try {
const clanTag = formData.get("clanTag");
const response = await fetch(ENDPOINT_CHANGE_CLANTAG, {
method: 'POST',
headers: getDefaultHeader(sessionToken),
body: JSON.stringify({clanTag: clanTag}),
});
const result = await response.json();
console.error("result", result);
revalidatePath(prevState.path ?? "/");
return {
message: `Success`,
response: result,
};
} catch (e) {
return {
message: "Error",
};
}
}Answered by Beveren
ok got it, removed the try/catch which then printed the error:
There was a stray "use client" in my util .ts file of "getDefaultHeader()"
There was a stray "use client" in my util .ts file of "getDefaultHeader()"
1 Reply
BeverenOP
ok got it, removed the try/catch which then printed the error:
There was a stray "use client" in my util .ts file of "getDefaultHeader()"
There was a stray "use client" in my util .ts file of "getDefaultHeader()"
Answer