Skip to content
Discussion options

You must be logged in to vote

My current solution :

When fetching data send cookie

import { getSession } from "next-auth/react";

export async function getServerSideProps(context) {
  const session = await getSession(context);
  if (!session) {
    return {
      redirect: {
        destination: "/warning",
        permanent: false,
      },
    };
  }
  if (session && session.user.role === "ADMIN") {
    const DBdata = await axios
      .get(`${process.env.NEXTAUTH_URL}/api/backend/something`, {
        headers: { Cookie: context.req.headers.cookie },
      })
      .then((res) => res.data)
      .catch((error) => console.log(error));

    return {
      props: { session: JSON.parse(JSON.stringify(session)), DBdata }…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Sakkhor909
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant