Skip to content

Fix redirectTo function w/ blank to behave like blank redirectTo (fix)#183

Merged
mrlannigan merged 1 commit intohapijs:masterfrom
flippidippi:master
Feb 8, 2018
Merged

Fix redirectTo function w/ blank to behave like blank redirectTo (fix)#183
mrlannigan merged 1 commit intohapijs:masterfrom
flippidippi:master

Conversation

@flippidippi
Copy link
Copy Markdown
Contributor

Fixing #169 pull request. I destroyed it.

Currently when redirectTo is a function and the function returns blank, hapi-auth-cookie stills tries to do the redirect instead of behaving like redirectTo: undefined. Fixing this will allow issues like #144 where you might want different behavior on an API call vs the browser.

This change will allow something like following code to redirect or not according to a header set

redirectTo (request) {
  const requestedWith = request.headers['x-requested-with'] && request.headers['x-requested-with'].toLowerCase()
  if (requestedWith && (requestedWith === 'ajax' || requestedWith === 'xmlhttprequest')) {
    return undefined
  } else {
    return '/login'
  }
}

@flippidippi
Copy link
Copy Markdown
Contributor Author

@mrlannigan looks like there all no conflicts, can we get this merged soon?

@mrlannigan mrlannigan modified the milestones: 8.0.1, 8.1.0 Jan 20, 2018
@mrlannigan mrlannigan merged commit 3361ea6 into hapijs:master Feb 8, 2018
@mrlannigan
Copy link
Copy Markdown
Contributor

Published with v8.0.1

@lock
Copy link
Copy Markdown

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Bug or defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants