I have a nextjs application with simple user authentication. That means there are some protected routes that I don't want logged out user to get access to. The app compiles successfully in development build and works as expected. But when I use next build, I get an error saying -
Error occurred prerendering page "/createNewAdditionalInfo". Read more: https://err.sh/next.js/prerender-error
Error: 'redirect' can not be returned from getStaticProps during prerendering (/createNewAdditionalInfo).
Here's the code -
export async function getStaticProps(ctx) {
let userObject;
let id;
const cookie = parseCookies(ctx);
if (cookie.auth) {
userObject = JSON.parse(cookie.auth);
id = userObject.id;
}
if (!id) {
return {
redirect: {
permanent: false,
destination: '/',
},
};
}
return {
props: {},
};
}