Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Future<Null> _ensureLoggedIn(String teamID) async {
if (currentUser == null)
// Não está logado
currentUser = await _googleSignIn.signInSilently();
if (currentUser == null) currentUser = await _googleSignIn.signIn();
if (await _auth.currentUser() == null) {
// Verificando se o usuário no Firebase é nulo
GoogleSignInAuthentication credentials =
await _googleSignIn.currentUser.authentication;
// Gerando a chave usando as credenciais do Google
if (currentUser.id != null) {
var key = sha1.convert(utf8.encode(currentUser.id));
_chatUID = key.toString();
_chatHelper = ChatHelper();
_chatKey = ChatKey();
_chatKey.firebaseUser = currentUser.id;
_chatKey.chat = teamID + "__#__" + key.toString();
_chatHelper.save(_chatKey);
// Salvando o usuário localmente
CurrentUserHelper _userHelper = CurrentUserHelper();
CurrentUser _user = CurrentUser();
_user.firebaseToken = credentials.idToken;
_user.googleToken = currentUser.id;
_user.token = currentUser.id;
_user.email = currentUser.email;
_user.name = currentUser.displayName;
_userHelper.save(_user);
}
final AuthCredential _authCredential =
GoogleAuthProvider.getCredential(
accessToken: credentials.accessToken,
idToken: credentials.idToken);
var firebaseAuthUser = await _auth.signInWithCredential(_authCredential);
// Criar o canal de mensagens no firebase
_chatHelper = ChatHelper();
var itens = await _chatHelper.all();
for (var item in itens) {
_chatUID = item["chatColumn"];
}
Firestore.instance
.collection("chats")
.document(_chatUID)
.setData({"from": currentUser.displayName, "to": teamID.toString()});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.