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

Custom response on normal request and AJAX #144

Closed
odorisioe opened this issue Sep 22, 2016 · 2 comments
Closed

Custom response on normal request and AJAX #144

odorisioe opened this issue Sep 22, 2016 · 2 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@odorisioe
Copy link

Hello, I wonder how i can customize the response on two different situations:

On a normal request, if the URL requires session, I want to redirect to a /login page.
Here I can set the option "redirectTo" with "/login".

On a ajax request, I want to return a custom JSON. But If I add the "redirectTo" I get a redirect to /login

I am trying to use Hapi without a client (like angular/react) so I am looking use both options on the Hapi side.
Is there any way to do it?

Thanks for your time!

@jaw187 jaw187 self-assigned this Feb 17, 2017
@jaw187
Copy link
Contributor

jaw187 commented Feb 17, 2017

@odorisioe You will need to setup a specific route which uses try mode. Then in your code you'll need an assertion which checks if authenticated. When you have a request which is not authenticated, you should respond with your error payload.

@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
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants