For example, assume I have a page called internal.tsx that has:
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const session = await getSession(ctx);
if (!session) {
// TODO: Add a toast notification explaining the redirect. Ideally, the desired destination should be remembered and should be redirected to after login.
return {
redirect: {
destination: '/',
permanent: false,
},
};
}
const props = ...
return { props };
};
If a visitor browses to this page at /internal, they will get bounced to my signin page without explanation.
I instead want my signin page to show a toast notification at the top of the screen explaining that the page they tried to access requires a login and that they will be returned to that page once they log in.
I plan to use a library like https://github.com/fkhadra/react-toastify on the signin page but haven't been able to figure out how / where to read from the session that the visitor had just been redirected.
Ideally each page (such as /internal
) initiating a redirection could specify its own custom message (e.g. saved to a "flash variable" in the session) for the signin page to display in the toast.