Firebase CPP身份验证崩溃

时间:2018-09-02 20:50:27

标签: c++ firebase firebase-authentication

我有一个非常简单的firebase身份验证代码。但是,当我尝试通过SignInWithEmailAndPassword函数访问用户数据时,它会崩溃。

由于崩溃,我无法从User对象检索用户信息。有什么我想念的吗?

这是我的代码:

@types

这是我的系统信息:

bool Initialize() {
if (!_firebaseApp) {
    _firebaseApp = App::Create();
}

if (!_firebaseApp) {
    return false;
}

InitResult authInitResult;
_firebaseAuth = Auth::GetAuth(_firebaseApp, &authInitResult);
if (authInitResult != InitResult::kInitResultSuccess) {
    return false;
}
_firebaseDatabase = Database::GetInstance(_firebaseApp);
return true;
}

bool Authenticate(const char* email, const char* password, bool sync) {
if (!_firebaseAuth) {
    printf("Auth is not initialized!\n");
    return false;
}

auto lastAuthResult = _firebaseAuth->SignInWithEmailAndPasswordLastResult();
if (lastAuthResult.status() == firebase::kFutureStatusInvalid ||
    (lastAuthResult.status() == firebase::kFutureStatusComplete &&
    lastAuthResult.error() != firebase::auth::kAuthErrorNone)) {
    auto authResult = _firebaseAuth->SignInWithEmailAndPassword(email, password);
    authResult.OnCompletion([](const Future<User*>& future) {
    authError = static_cast<AuthError>(future.error());
    if (authError == kAuthErrorNone) {
        printf("Auth: signing in successful %s\n", _firebaseAuth->current_user()->email().c_str());
    }
    cvAuth.notify_all();
    });
}

if (isSignedIn(lastAuthResult)) {
    printf("Signing in successful\n");
    return true;
}

if (sync) {
    unique_lock<mutex> authLock(_mutex);
    printf("Waiting for authentication!\n");
    cvAuth.wait(authLock);
    authLock.unlock();
}

bool is = isSignedIn(_firebaseAuth->SignInWithEmailAndPasswordLastResult());
printf("Is signed in? %d\n", is);
return is;
}

LDD结果

Linux autoxdl-070 4.15.0-33-generic #36~16.04.1-Ubuntu SMP Wed Aug 15 17:21:05 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

崩溃回溯:

ldd ./bin/fb_auth_demo
        linux-vdso.so.1 =>  (0x00007fffdeda2000)
        libprotobuf.so.9 => /usr/lib/x86_64-linux-gnu/libprotobuf.so.9 (0x00007f5133fd6000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5133c54000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f513394b000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5133735000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5133518000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f513314e000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5132f34000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f51342f4000)

0 个答案:

没有答案