0

I have a GET /auth route that accept request and need to do a redirect to an external resource (let's say https://google.com), but instead of redirecting me to https://google.com it redirects me to http:localhost:3000/api/auth/https://google.com.

Is that possible to redirect to an external resource somehow? Cause now it searches for the path https://google.com in my route.

Here is my router:

export const loginController = async (req: Request, res: Response, next: NextFunction) => {
  res.redirect('https://google.com');
};

router.get('/login', loginController);
Karen
  • 1,249
  • 4
  • 23
  • 46
  • What library are you using for the server? Try this: https://stackoverflow.com/questions/11355366/how-to-redirect-users-browser-url-to-a-different-page-in-nodejs – Amats Dec 17 '20 at 15:00

1 Answers1

0

You need to use query parameters like this:

http:localhost:3000/api/auth?redirectUrl=https://google.com
export const loginController = async (req: Request, res: Response, next: NextFunction) => {
  const { redirectUrl } = req.query
  res.redirect(redirectUrl);
};
Anatoly
  • 20,799
  • 3
  • 28
  • 42