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

Login returns 500: Internal server error #54

Closed
wuyuanyi135 opened this Issue Feb 12, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@wuyuanyi135
Copy link

wuyuanyi135 commented Feb 12, 2016

I just followed the doc to create an authentication app

var feathers = require('feathers');
var hooks = require('feathers-hooks');
var bodyParser = require ('body-parser');
var authentication = require ('feathers-authentication').default;
var authHooks = require('feathers-authentication').hooks;
var mongoose = require('mongoose');

var userModel = require ('../model/user-model');
var service = require ('feathers-mongoose');

var app = feathers()
    .configure(feathers.rest())
    .configure(hooks())
    .use(bodyParser.json())
    .use(bodyParser.urlencoded({ extended: true }))
    .configure(authentication({
        secret: '123',
        loginEndpoint: '/login',
    }));

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/user');


app.use('/', service({Model: userModel}));

var userService =  app.service('/');

userService.before(
    {
        create: [authHooks.hashPassword('password')]
    }
)
module.exports=app;

I only changed the loginEndpoint to where I want. The create action is done properly. However, the login request POST http://localhost:8080/riddle/api/user/login with payload {"username":"yyy","password":"xxx"} returns 500: Internal Server Error and an empty json object, no stack trace at all.

There was no any output on the console. Did I miss any dependency?

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Feb 12, 2016

Which version of the feathers-authentication plugin do you have installed?

@wuyuanyi135

This comment has been minimized.

Copy link
Author

wuyuanyi135 commented Feb 12, 2016

its 0.1.2. Was it broken due to the feathers updating?
I found that was not the latest so I start working on 0.2.0 with the example on github.
I found that in 0.2.0, the auth is not the same. I don't know what should I post to the endpoint /auth/local, a json or a url encoded data.

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Feb 12, 2016

Use JSON with POST. I have yet to use the 0.2.0, which was published last night. Do you want to make a repo with your code?

Otherwise, I usually use Visual Studio Code for its great, fast debugger. Put a debugger; statement in your code and run node debug src then use VS Code's debugger in "attach" mode and you'll be able to step through the code to find the error. You might also be able to get a better error message with the error handler in the feathers generator.

screen shot 2016-02-12 at 10 02 13 am

screen shot 2016-02-12 at 10 00 45 am

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Feb 12, 2016

Or just wait until the docs are finished for 0.2.0 :)

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Feb 12, 2016

@wuyuanyi135 You aren't too far off. The API in 0.2.0 did change slightly.

Instead of:

.configure(authentication({
        secret: '123',
        loginEndpoint: '/login',
    }));

You need to do this:

.configure(authentication({
  token: {
    secret: '123',
  },
  local: {
    localEndpoint: '/login',
  }
}));

Now I found a bug with the localEndpoint not being overriden by the value you pass in so I'm working on that right now, but the default endpoint is now /auth/local so you could just post to that.

Apologies for the confusion but until we get to a 1.0.0 for feathers-authentication some stuff may be changing. Probably not much more now it's mostly just documenting and testing.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Feb 12, 2016

Alright I've fixed the issue (#55) where custom local options were not being picked up. So you can do this:

.configure(authentication({
  token: {
    secret: '123',
  },
  local: {
    localEndpoint: '/login',
  }
}));
@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Feb 12, 2016

@wuyuanyi135 I'm going to close this now. I've tested it and your custom endpoint should work if you change up your config. I'll have new docs up soon that explain all the different config options.

@ekryski ekryski closed this Feb 12, 2016

@wuyuanyi135

This comment has been minimized.

Copy link
Author

wuyuanyi135 commented Feb 12, 2016

Thank you guys. I will try the latest version. Also thanks @marshallswain for your debugging tips. I will look into that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.