Namespace: Urls:addNextParameter

Urls:addNextParameter

Source:

Methods

addNextParameter(urlopt, nullable, nextopt, nullable, paramNameopt, nullable, assertSameBaseDomainopt, nullable, additionalTopLevelDomainsopt, nullable) → {String}

Adds a "next"-parameter to a given URL. If there is already a parameter of that name, it will be replaced.

A "next"-parameter is usually used to relay a second URL, which should be redirected to after something happens, such as a login or another (possibly automatic) action.

Parameters:
Name Type Attributes Default Description
url String <optional>
<nullable>
''

the URL to add the next parameter to, if left empty, will be "", which is synonymous with the current URL

next String <optional>
<nullable>
''

the next URL to add as parameter to the given URL (will automatically be URL-encoded)

paramName String <optional>
<nullable>
'next'

the name of the next parameter

assertSameBaseDomain Boolean <optional>
<nullable>
false

if true, url and next must have the same base domain (ignoring subdomains), to prevent injections

additionalTopLevelDomains Array.<String> <optional>
<nullable>
null

this function uses a list of common TLDs (if assertSameBaseDomain is true), if yours is missing, you may provide it, using this parameter

Source:
See:
Throws:
  • error if url or next are not usable URLs

  • error if assertBaseDomain is true an the base domains of url and next differ

Returns:
the transformed URL with the added next parameter
Type
String
Example
addNextParameter('https://foobar.com', 'https://foo.bar', 'redirect');
=> 'https://foobar.com?redirect=https%3A%2F%2Ffoo.bar'
addNextParameter('https://foobar.com?next=https%3A%2F%2Ffoo.bar', 'https://kittens.com');
=> 'https://foobar.com?next=https%3A%2F%2Fkittens.com'