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

How to "decorate the response with authentication headers" in responseFunc #199

Open
przemyslaw-wlodek opened this issue Oct 10, 2016 · 2 comments
Labels

Comments

@przemyslaw-wlodek
Copy link

I'm sorry, but I'm new to HapiJS, and I don't truly understand how responseFunc works.
I want to return new token in every response, so I created a function:

function refreshSession(request, reply) {
  const { response } = request;
  const { exp, userId } = request.auth.credentials;

  // if token has expiry date then create and send new session token with each request

  if (exp) {
    response.header('Authorization', session.create(userId));
  }

  reply.continue(); // < --- is it correct?
}

Documentation says: reply(err, response) - is called if an error occurred.
So I've tried many variations with passing arguments to reply, but it never worked properly.

I'm asking to be sure if above is right or it if has some hidden pitfalls.

Thanks in advance.

@nelsonic
Copy link
Member

@xgarrett are you returning a new token on each response for security reasons?

@przemyslaw-wlodek
Copy link
Author

No. I'm doing it when user doesn't want to have "infinite" session. Then session token stays valid for ~2hours, I'm returning new to maintain 2h from last request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants