poeticninja / hapi-authentication-and-authorization

Authentication and Authorization with Hapi.js
MIT License
52 stars 14 forks source link

Unable to login succesfully #2

Open heron2014 opened 8 years ago

heron2014 commented 8 years ago

Hi @poeticninja. We are trying to run your example but have come across an issue where we are unable to set cookie object. We think this is where the problem is : L50

And this is the error from the console : error1

We hope you can help out. Thanks

poeticninja commented 8 years ago

I just ran a clean install of this project and it worked. I cloned the repo into a new directory, ran npm install, I am on Node 5.1.1, and no problems doing the login with Postman (https://www.getpostman.com/).

Did you modify any of the code in the project or change the dependencies in the package.json to a newer version?

heron2014 commented 8 years ago

We haven't used Postman because we added view with the form here. package.json looks the same as ours, we only added few dependencies for view rendering. The only difference is that I am using node 4.1. I will update node and see if that might be an issue.

lshiffer commented 8 years ago

I'm getting the same error, running node 4.2.4.

The issue is request.auth.session.set(user), as noted by OP.... Doing a print out of the request object's '.auth' there is no 'session'. "request.auth.session" is undefined.

I also get the same error running /logout with the 'request.auth.session.clear()'. "Cannot read property 'clear' of undefined".

Any suggestions? I suspect it might be Hapi 12.1 compared to v8 in the project. I believe some stuff was removed from Hapi since then and became add-ons... But I'm not sure how to remedy.

lshiffer commented 8 years ago

I can confirm that the difference is in Hapi's version.

'"Starting with Hapi 12 the request.session placeholder was removed."

It is now in a plugin known as 'Yar' (https://github.com/hapijs/yar).

Using Yar I was able to overcome the login and logout errors. However, I don't believe the session is properly being set as when I go to a protected route I get a 'Missing authentication' message.

Any ideas? Thank you.

davidenq commented 8 years ago

I'm submitting a pull request. I’ve made some slight modifications, as es5 to es6 style , refactoring and updating dependecies. But it retains the original idea. Now this example Hapijs work with version 12.1.0.