使用 Google 进行身份验证时创建新用户

时间:2021-03-05 08:44:16

标签: firebase react-native

当我第一次或多次进行身份验证时,如何在 firebase 中创建文档用户???

示例:我选择通过 google、Twitter .... 通过帐户 abc@gmail.com 进行身份验证 ...并且我想使用 document = User UId(google 帐户)保存到集合“user”。

使用证书身份验证方法,我不知道如何获取 Google 用户用户 UID,直到将其添加到身份验证列表中。

signInWithGoogleAsync = async () => {
    try {

      const { type, accessToken } = await Google.logInAsync({
        iosClientId: '1058889369323-kh44jtru0ar24qu24ebv1bu0ebrgvokd.apps.googleusercontent.com',
        scopes: ['profile', 'email'],
      });

      if (type === 'success') {
        this.setState({ spinner: true });
        const credential = firebase.auth.GoogleAuthProvider.credential(null, accessToken);
        firebase.auth().signInWithCredential(credential).catch(error => {console.log(error);});

///I know how to do this, authenticate 1 user and put it in the Authentication list when authenticating successfully the first time     

  } else {
        return { cancelled: true };
      }
    } catch (e) {
      return { error: true };
    }
  }

0 个答案:

没有答案