Error handling in Apollo Server GraphQL not redirecting to login page
// Error handling code in Apollo Client onError(({ graphQLErrors, networkError }) => { if (graphQLErrors) { graphQLErrors.forEach(({ message, locations, path }) => { console.log( `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}` ); if (message.includes(“not authenticated”)) { if (typeof window === “undefined”) { ctx.res?.writeHead(302, { Location: “/login” }); ctx.res?.end(); } else { useRouter().replace(“/login”); } } … Read more