Skip to content

Commit

Permalink
extract domain from referer
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Feb 12, 2024
1 parent d7d21c7 commit cbc39b9
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type PassportCallbackAuthenticateMiddlewareOptions = {
failureRedirect: string;
};

const extractDomain = (url) => {
const domain = url.match(/^(?:https|http?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
return domain;
};

/**
* Build and return a router including the different route and configuration for a passport strategy
* @param domain
Expand Down Expand Up @@ -128,7 +133,7 @@ function successActionHandlerFactory(
const returnAccessToken = req.query.returnAccessToken == 'true';
const redirectUrl = (req.query.redirectTo ? req.query.redirectTo : defaultRedirect) as string;
const isProdOrStaging = process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging';
const originHost = isProdOrStaging ? req.get('referer') : undefined;
const originHost = isProdOrStaging ? req.get('referer') && extractDomain(req.get('referer')) : undefined;

if (returnAccessToken) {
return (req: Request, res: Response) => {
Expand Down

0 comments on commit cbc39b9

Please sign in to comment.