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

Can't get success authorization with pure feathers server #491

Closed
olegggI opened this Issue Apr 24, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@olegggI
Copy link

olegggI commented Apr 24, 2017

Always have an error from the server:
{"name":"NotAuthenticated","message":"Error","code":401,"className":"not-authenticated","errors":{}}
And Status Code:401 Unauthorized
What i already done:

  1. feathers generate app
  2. feathers generate authentication (NeDB, users)

Then, i created a user (email: 'admin@feathersjs.com', password: 'admin') and test-client for authentication:

    // Set up socket.io
    var host = 'http://localhost:3030';
    // Set up Feathers client side
    var app = feathers();
    // Register hooks module
    app.configure(feathers.hooks());
    // Register socket.io
    app.configure(feathers.rest(host).fetch(window.fetch.bind(window)))
    // Set up authentication with a store to cache your auth token
    app.configure(feathers.authentication({ storage: window.localStorage }));
    // Authenticating using a email and password
    app.authenticate({
      strategy: 'local',
      email: 'admin@feathersjs.com',
      password: 'admin'
    }).then(function(result){
      console.log('Authenticated!', result);
     // Find our users on the server via sockets
      app.service('users').find({}).then(function(users){
        console.log('Users!', users);
      });
    }).catch(function(error){
      console.error('Error authenticating!', error);
    });

What i did wrong?

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 26, 2017

Can you share an application where it is possible to reproduce the error? Those steps seem to be working with the feathers-chat repository.

@olegggI

This comment has been minimized.

Copy link
Author

olegggI commented Apr 26, 2017

@daffl Sure

git clone https://github.com/olegggI/feathers.git
cd feathers
npm install
npm start

@olegggI

This comment has been minimized.

Copy link
Author

olegggI commented Apr 27, 2017

@daffl any ideas? :)

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Apr 27, 2017

@olegggI try returning a value for your promises. If you don't return a value, everything further down the promise chain will have nothing to act on.

// Set up socket.io
    var host = 'http://localhost:3030';
    // Set up Feathers client side
    var app = feathers();
    // Register hooks module
    app.configure(feathers.hooks());
    // Register socket.io
    app.configure(feathers.rest(host).fetch(window.fetch.bind(window)))
    // Set up authentication with a store to cache your auth token
    app.configure(feathers.authentication({ storage: window.localStorage }));
    // Authenticating using a email and password
    app.authenticate({
      strategy: 'local',
      email: 'admin@feathersjs.com',
      password: 'admin'
    }).then(function(result){
      console.log('Authenticated!', result);
     // Find our users on the server via sockets
      return app.service('users').find({}).then(function(users){
        console.log('Users!', users);
return result;
      });
    }).catch(function(error){
      console.error('Error authenticating!', error);
    });
@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Jun 1, 2017

@olegggI did my suggestion help? Feel free to reopen this if needed.

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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.