feathersjs-ecosystem/feathers-react-native-chat

No response after clicking login button

shsunmoonlee opened this issue · 6 comments

Hi, I'm running it on android studio emulator and while my feathers-react feathers-chat are working fine, double checked my server is running fine, this app isn't working.
server: http://localhost:3030

I would appreciate your help. thanks

In the Android Emulator you can’t use localhost, you have to use 10.0.2.2

Thank you so much!
Then why did people leave the code in this repo as http://localhost:3030 ?
How else people run the app other than using android studio Emulator?

Because localhost works on iOS. You’d have to use the actual IP for a physical iOS or Android device.

Everything is clear now. thanks again!

Now socket is connected but still I dont' get resposne from login. I re wrote the login part like this. I would appreciate your help. thanks

    try {
      const response = await feathers.authenticate({
        strategy: 'local',
        email, password
      })
      console.log("=======first response", response)
      const response2 = await feathers.passport.verifyJWT(response.accessToken)
      console.log("=======second response", response2)

      try {
        const user = await feathers.service('users').get(payload.userId);
        console.log("=======user response", user)

        this.props.login({user, isAuthenticated: true})
        // this.user = user;
        // this.isAuthenticated = true;
        console.log("===received user information", user)
      } catch(e) {
        console.log("authentication failed", e)
      }
    } catch(e) {
      console.error('Authentication error', e);
    }
//featherrs.js
import {Alert, AsyncStorage} from 'react-native';
import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
import io from 'socket.io-client'
import auth from '@feathersjs/authentication-client'
const PLACEHOLDER = 'https://raw.githubusercontent.com/feathersjs/feathers-chat/master/public/placeholder.png';
const API_URL = 'http://10.0.2.2:3030';
const options = {transports: ['websocket'], pingTimeout: 10000, pingInterval: 50000};

const socket = io(API_URL, options);
const FeathersClient = feathers();

FeathersClient.configure(socketio(socket))
FeathersClient.configure(auth({
  storage: AsyncStorage // To store our accessToken
}));

export default FeathersClient;


error log: WebsocketModule.close got 1 arguments, expected 3.

====EDIT
It's working now! the problem was in my rootcontainer.

class RootContainer extends Component {
  async componentDidMount () {
    // if redux persist is not active fire startup action
    if (!ReduxPersist.active) {
      this.props.startup()
    }
    /**
     * feathers server connect
     */
    console.log("====FeathersClient is Connecting")
    feathers.io.on('connect', async () => {
      console.log("====FeathersClient is Connected")

      try {
        const response = await feathers.authenticate({undefined})
        console.log("=======first response", response)
        const response2 = await feathers.passport.verifyJWT(response.accessToken)
        console.log("=======second response", response2)
      
        try {
          const user = await feathers.service('users').get(payload.userId);
          console.log("=======user response", user)
      
          this.props.login({user, isAuthenticated: true})
          // this.user = user;
          // this.isAuthenticated = true;
          console.log("===received user information", user)
        } catch(e) {
          console.log("authentication failed", e)
        }
      } catch(e) {
        console.error('Authentication error', e);
      }

    });

    feathers.io.on('disconnect', () => {
      console.log('disconnected');
      this.isConnecting = true;
    });
  }

What should I pass to check if there is user authenticated already? I thought I have to get info from asyncStorage but in this repo, it is passing 'undefined' to feathers.authenticate(undefined) .

Does anyone know what's the best practice? To me it makes sense to connect, check user signed at the rootcontainer componentDidMount.

You should pass nothing to authenticate and it will use the token stored in storage, which in this repo is AsyncStorage. And yes, componentDidMount makes sense.