JS: How to pass url through redirect function to login function

In your with-server-props.js replace the path with an URL object

redirect(context, {
    pathname: '/',
    query: { redirect: req.url } // req.url should give you the current url on server side

this will add a redirect param to the url https://example.com/?redirect=/about

then you can get the url params on any page using the getInitialProps:

this.redirectUrl = (req && req.query['redirect']) ? decodeURIComponent(req.query['redirect']) : '/'



hope it helps, let me know.