Skip to content
Discussion options

You must be logged in to vote

I also had the same problem and this is how I did it.

export const getServerSideProps = async (ctx) => {
	const session = await getSession(ctx);
	const headers = ctx.req.headers;
	try {
		if (session) {
			const projects = (
				await axios.get(`${process.env.NEXTAUTH_URL}/api/projects`, {
					headers: { Cookie: headers.cookie },
				})
			).data;
			return {
				props: {
					projects,
				},
			};
		} else {
			return {
				redirect: {
					destination: `/login`,
					permanent: false,
				},
			};
		}
	} catch {
		return {
			redirect: {
				destination: '/error/403',
				permanent: false,
			},
		};
	}
};

`

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@corysimmons
Comment options

@hanbrandon
Comment options

Answer selected by corysimmons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants