'How to send JWT token as query param in NEXT js?

const Jwt = (props) => {
  const { jwt } = props;
  const [jwtToken, setJwtToken] = useState(null);

  useEffect(() => {
    if (jwt) {
      setAuthToken(jwt);
      setJwtToken(jwt);
    }
  }, [jwt]);

  return <MobilePurchaseScreen {...props} />;
};

export const getServerSideProps = async (context) => {
  const { query } = context;
  const { jwt } = query;
  return {
    props: {
      jwt,
    },
  };
};

export default Jwt;

I am using next js where I have sending JWT token as path directly, How can I send it as query param.



Solution 1:[1]

I dont think it is safe to send jwt as query param unless it is one time use only. Because If someone grabs it can use it. To get jwt as query you have to set it first:

  <Link href=`/post/abc?jwt=${jwtTokenHere}`>
      <a>Visit the post/abc/jwt=</a>
    </Link>

Then when you visit that page, in getServerSideProps:

export async function getServerSideProps(context) {
  const { jwt } = context.query;

  console.log(`jwt: ${jwt}`);
  return { props: { jwt } };
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yilmaz