connect-vtexid
Version:
VTEX ID Authentication middleware for Connect
31 lines (23 loc) • 797 B
text/coffeescript
###
Module dependencies.
###
getRedirectSettings = (options, returnUrl) ->
#getRedirectSettings = (defaultRedirectUri, returnUrl, useReturnUrl) ->
throw new Error '"options" parameter is required' if not options?
defaultRedirectUri = options.redirectUrl
useReturnUrl = options.useReturnUrl
logoutUrl = options.logoutUrl
returnUrlParts = returnUrl.split('?')
returnUrl = returnUrlParts[0]
if returnUrlParts.length > 1
previousUrl = returnUrlParts[1].split('=')[1]
if(returnUrl is logoutUrl)
returnUrl = previousUrl
returnUrl = returnUrl.replace(/\/$/, '')
redirectUrl = defaultRedirectUri
redirectUrl = "#{defaultRedirectUri}#{returnUrl}" if useReturnUrl
return {
returnUrl: returnUrl
redirectUrl: redirectUrl
}
module.exports = getRedirectSettings