Well after a lot of research I found out that trying to do a redirect from an AJAX call is a big no no, that's what was causing the issue. I have reverted to returning an redirect url and then redirecting to that from the frontend.