failed to fetch rsc payload while using NextAuth
Unanswered
Tibetan Terrier posted this in #help-forum
Tibetan TerrierOP
Hey! I am using NextAuth+Google for auth and it's working super well on other devices except iOS safari and the other webkit browsers. All I get is this error-
Was having the same error with Discord.
Will appreciate any help. Thank you.
ERRORFailed to fetch RSC payload. Falling back to browser navigation. TypeError: Load failed.
Was having the same error with Discord.
Will appreciate any help. Thank you.
5 Replies
Tibetan TerrierOP
Possible related issue- https://github.com/vercel/next.js/issues/48677
Tibetan TerrierOP
any inputs?
Argente Brun
Hello friends. I found out that its easier to just turn your route into a client-side redirect after you set your cookies.
Here is an example:
(using Next 15.0.1)
Hope this helps.
Here is an example:
(using Next 15.0.1)
import { cookies } from "next/headers";
import { generateState } from "arctic";
import { discord } from "@/lib/auth";
import { env } from "@/env";
export async function GET(): Promise<Response> {
const sessionCookies = await cookies();
const state = generateState();
const url = discord.createAuthorizationURL(state, [
"identify",
"email"
]);
sessionCookies.set("discord_oauth_state", state, {
path: "/",
secure: env.NODE_ENV === "production",
httpOnly: true,
maxAge: 60 * 10,
sameSite: "lax",
});
// Return HTML that performs the redirect
const html = `
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0;url=${url.toString()}">
</head>
</html>
`;
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
}Hope this helps.
Argente Brun
Another solution is to create a promise on your API route, and have your link/button wait for that promise then redirect.
const handleDiscordLogin = async () => {
setIsDiscordLoading(true);
try {
const response = await fetch('/login/discord');
const data = await response.json();
router.push(data.url);
} catch (error) {
setIsDiscordLoading(false);
}
};Example promise and response I have set.