Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 8, 2018
Merged

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

merged 1 commit into from
Feb 8, 2018

Conversation

flippidippi
Copy link
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
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
Contributor

Published with v8.0.1

@lock
Copy link

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