我正在使用 Firebase SimpleLogin 启用电子邮件/密码身份验证。用户的创建和后续登录一切正常。然而,每当我离开应用程序(即使只有几秒钟),用户在我返回时永远不会登录,即......
authClient.checkAuthStatus(new SimpleLoginAuthenticatedHandler())...
始终返回空用户。
我不会通过 API 注销用户。另外,我在 Firebase 控制台中将用户登录的天数设置为 21。
我在 JS 文档中看到提到了 Remember-me 参数,但我看不到 Android/Java 的任何等效参数。
想知道我是否遗漏了文档中的任何内容或者 Android 是否无法实现?
感谢您的帮助,
Neil.
编辑:添加了代码示例。
用户创建....
public void registerUserForChat(final MyApplication application, String email, String password) {
Firebase ref = new Firebase(FIREBASE_URL);
SimpleLogin authClient = new SimpleLogin(ref);
authClient.createUser(email, password, new SimpleLoginAuthenticatedHandler() {
@Override
public void authenticated(com.firebase.simplelogin.enums.Error error, User user) {
if(error != null) {
Log.e(TAG, "Error attempting to create new Firebase User: " + error);
}
else {
Log.d(TAG, "User successfully registered for Firebase");
application.setLoggedIntoChat(true);
}
}
});
}
用户登录....
public void loginUserForChat(final MyApplication application, String email, String password) {
Log.d(TAG, "Attempting to login Firebase user...");
Firebase ref = new Firebase(FirebaseService.FIREBASE_URL);
final SimpleLogin authClient = new SimpleLogin(ref);
authClient.checkAuthStatus(new SimpleLoginAuthenticatedHandler() {
@Override
public void authenticated(com.firebase.simplelogin.enums.Error error, User user) {
if (error != null) {
Log.d(TAG, "error performing check: " + error);
} else if (user == null) {
Log.d(TAG, "no user logged in. Will login...");
authClient.loginWithEmail(email, password, new SimpleLoginAuthenticatedHandler() {
@Override
public void authenticated(com.firebase.simplelogin.enums.Error error, User user) {
if(error != null) {
if(com.firebase.simplelogin.enums.Error.UserDoesNotExist == error) {
Log.e(TAG, "UserDoesNotExist!");
} else {
Log.e(TAG, "Error attempting to login Firebase User: " + error);
}
}
else {
Log.d(TAG, "User successfully logged into Firebase");
application.setLoggedIntoChat(true);
}
}
});
} else {
Log.d(TAG, "user is logged in");
}
}
});
}
因此,loginUserForChat 方法首先检查是否有登录用户,如果没有,则执行登录。请注意,每次我启动应用程序时,我看到的日志记录都是......
- 正在尝试登录 Firebase 用户...
- 没有用户登录。将登录...
- 用户成功登录 Firebase
如果我退出应用程序,即使是几秒钟,然后返回 - 我会看到相同的日志记录。
我注意到的一件事是调用检查验证状态不获取任何用户凭据 - 我认为它只是检查any本地登录的用户?
非常感激。