I have a React Native app where the user can login with email and the regular accounts system and that all works fine.
I’ve added my own Facebook login to RN and it logs the user in on the client, but on the server the user is still logged out. The publications have this.userId set to null after login, but the user sees the logged in views in my RN app.
If I restart my RN app the user is fully logged in and the server even has the user as logged in.
Does anyone have an idea of how I got to this state of the login process having completed, but the this.userId still set to null in publications on the server?
So after some more investigating, the reason it works when I login with FB and then restart the app is because it’s using the resume token to do the login and that works fine.
Another thing is that this whole process works fine on my iOS simulator and it’s just when testing on my Android phone I get the issues upon login.
I’m not sure why this would only happen on Android but I think I’ve had an issue similar to the login but userId not being set until reload.
After successfully signing in, in my callback I believe I made a call to this function which then set the userId in all the necessary places so that it would be used by react-native-meteor when making method calls and pub/sub.
Something like this (untested code, just guessing)
import React, { AsyncStorage } from 'react-native';
import { AccessToken } from 'react-native-fbsdk';
import Meteor from 'react-native-meteor';
const USER_TOKEN_KEY = 'reactnativemeteor_usertoken';
export const loginWithTokens = () => {
const Data = Meteor.getData();
AccessToken.getCurrentAccessToken()
.then((res) => {
if (res) {
Meteor.call('login', { facebook: res }, (err, result) => {
if(!err) {//save user id and token
AsyncStorage.setItem(USER_TOKEN_KEY, result.token);
Data._tokenIdSaved = result.token;
Meteor._userIdSaved = result.id;
Meteor. _loginWithToken(result.id); // <=== _loginWithToken
}
});
}
});
};