Why are cookies not sent to the server via getServerSideProps in Next.js?

That’s because the request inside getServerSideProps doesn’t run in the browser – where cookies are automatically sent on every request – but actually gets executed on the server, in a Node.js environment. This means you need to explicitly pass the cookies to the axios request to send them through. export async function getServerSideProps({ req }) … Read more

Best HTTP Authorization header type for JWT

The best HTTP header for your client to send an access token (JWT or any other token) is the Authorization header with the Bearer authentication scheme. This scheme is described by the RFC6750. Example: GET /resource HTTP/1.1 Host: server.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIXVCJ9TJV…r7E20RMHrHDcEfxjoYZgeFONFh7HgQ If you need stronger security protection, you may also consider the following IETF … Read more

How to decode jwt token in javascript without using a library?

Working unicode text JWT parser function: function parseJwt (token) { var base64Url = token.split(‘.’)[1]; var base64 = base64Url.replace(/-/g, ‘+’).replace(/_/g, “https://stackoverflow.com/”); var jsonPayload = decodeURIComponent(atob(base64).split(”).map(function(c) { return ‘%’ + (’00’ + c.charCodeAt(0).toString(16)).slice(-2); }).join(”)); return JSON.parse(jsonPayload); };