feathersjs-ecosystem / feathers-react-native-chat

A React Native example chat app using feathers
196 stars 46 forks source link

Trouble running example #7

Closed kristianmandrup closed 8 years ago

kristianmandrup commented 8 years ago

Tried running example locally.

npm install
npm start

Then ran the xcode project in ios folder from Xcode. Created account credentials and clicked sign up. Then the app stalled on creating account...

<View style={{alignItems: 'center'}}>
  <Text>Creating account...</Text>
</View>

I would have assumed there would be some kind of timeout built in? Is that planned? I guess I need to set up the endpoint or start the server? Would be nice with some basic instructions :) Thanks.

    this.app.service('users').create(userData).then((result) => {
      this.app.authenticate({
        type: 'local',
        username: this.state.username,
        password: this.state.password
      }).then(response => {
        this.setState({ loading: false });
        // re-route to main authorized chat   component
        Actions.main();
      }).catch(error => {
        console.log(error);
        Alert.alert('Error', 'Please enter a valid username or password.');
        this.setState({ loading: false });
      });
    }).catch((err) => {
      console.log('err');
      console.log(err);
      self.setState({loading: false});
      Alert.alert('Error', err.message);
    });
  }

Trying to locate the socket setup, I see this:

export default class Application extends React.Component {
  constructor(props) {
    // ...
    const options = {transports: ['websocket'], forceNew: true};
    const socket = io('http://192.168.0.1:3030', options);

So it looks like the IP is hardcoded to 192.168.0.1. Which usually is just the IP for localhost Where is the feathersjs server I wonder? How do I start it? is this another project I need to spin up?

Also, trying to debug from Chrome via localhost:8081/debugger-ui caused a Not available error, as did http://localhost:8081/index.ios.bundle even though I find this in AppDelegate.m.

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

kristianmandrup commented 8 years ago

After having tried feathers-chat, I assume that this is just another client for the same server found there :)

kristianmandrup commented 8 years ago

Tried starting the feathers-chat server running on localhost:3030, but still getting the same error and no Chrome debug. I'm sure I'm on the right track however...

ekryski commented 8 years ago

@kristianmandrup

const socket = io('http://192.168.0.1:3030', options);

Accidentally checked that in, that was when we were testing on device.

I assume that this is just another client for the same server found there :)

Yup!

Let me just check to see what is going on. I may have some changes locally that I forgot to push.

kristianmandrup commented 8 years ago

Gracias! Perhaps you/we could detect if the server is up and running (at expected address/port) and display/log an error if not.

ekryski commented 8 years ago

@kristianmandrup OMG I forgot to check-in a shit ton of changes so that it works with the chat server. :faceplam:

Pushing up shortly and everything will work MUCH better. Damn, I had been directing people to the app thinking I had pushed the updates.

kristianmandrup commented 8 years ago

Sweet :) No worries, happens even for the best! hehe. Very typical

kristianmandrup commented 8 years ago

I hope it will include some sort of error handling as well. Would be nice to see some good sample code: http://docs.feathersjs.com/middleware/error-handling.html

ekryski commented 8 years ago

@kristianmandrup ok pushed up the latest. Hope that helps.

kristianmandrup commented 8 years ago

I get undefined is not an object, evaluating options.type. Perhaps set it to (options = {}) or even use a default type?

// Application.js#55

      this.app.authenticate().then(() => {
        this.setState({ loading: false });
        Actions.main();
      }).catch(error => {
    app.authenticate = function (options) {
      if (!options.type) {
        throw new Error('You need to provide a `type` attribute when calling app.authenticate()');
      }
ekryski commented 8 years ago

@kristianmandrup that has been fixed. Blow away your node_modules in the react native app and re-install. Which version of feathers-authentication do you have installed? You should have v0.5.1.

kristianmandrup commented 8 years ago
    "feathers": "2.0.0",
    "feathers-authentication": "^0.5.0",
$ npm install
feathersreactnativechat@0.1.0 /Users/kristianmandrup/repos/react-projs/feathers-react-native-chat
└── feathers-authentication@0.5.1

Sweet :)

ekryski commented 8 years ago

run npm ls feathers-authentication what does that output?

kristianmandrup commented 8 years ago

Haha :) Now I'm in trouble. I made so many signup attempts last time. Now I'm prompted with login only, but can't seem to find which signup credentials were successful (since no feedback).

How do I blast the nedb back to zero?

ekryski commented 8 years ago

@kristianmandrup just rm data/*.db

kristianmandrup commented 8 years ago

Well, I found this in the feathers-chat in services/user/index

  const db = new NeDB({
    filename: path.join(app.get('nedb'), 'users.db'),
    autoload: true
  });

Would be nice with the register button as well in case user wants to login/register as another user?

kristianmandrup commented 8 years ago

Gracias! Will do.

ekryski commented 8 years ago

@kristianmandrup you should be able to register and login as multiple users.

kristianmandrup commented 8 years ago

I checked, when I start the server data folder is empty. However I'm still always prompted with "welcome back" and login only. But I can close that window and register again. I see ;)

kristianmandrup commented 8 years ago

Wow it WUUURKZzzz!!!! Muchas Gracias!

ekryski commented 8 years ago

@kristianmandrup Ya it caches your token. Basically if it detects a previous token stored and the auth attempt fails, it assumes you logged in successfully at some point. So it directs you to the login screen. You can manually clear AsyncStorage or just remove the app from the simulator and rebuild it (or just log in again). Glad you got it working :smile:

kristianmandrup commented 8 years ago

Yeah! I was working on a similar RN chat app using Firebase and Gifted Messenger. But this one is beautiful and much simpler :) Inspired!

I also love the filter mechanics of FeathersJS, (currently reading the full ebook). Just what I was looking for. Considering writing a DB adapter for Datomic/Datascript... (clojure land). Cheers!

ekryski commented 8 years ago

@kristianmandrup awesome! We are always open to PRs! :smile:

kristianmandrup commented 8 years ago

Do you have a dev forum of some sort where we can have tech discussions, ideas etc. without bloating up these github issues :P

kristianmandrup commented 8 years ago

Very early attempt/start: https://github.com/kristianmandrup/feathers-datascript

ekryski commented 8 years ago

@kristianmandrup http://slack.feathersjs.com is currently the spot. We also have a public Trello board for the high level roadmap but we've been much more attentive to Github issues and Slack.