Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Login returns 500: Internal server error #54

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

Login returns 500: Internal server error #54

wuyuanyi135 opened this issue Feb 12, 2016 · 8 comments

Comments

@wuyuanyi135
Copy link

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
Copy link
Member

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

@wuyuanyi135
Copy link
Author

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
Copy link
Member

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
Copy link
Member

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

@ekryski
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
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
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 as completed Feb 12, 2016
@wuyuanyi135
Copy link
Author

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants