📦Implementação na Store
Exemplos de usos dos usecases de autenticação nas stores.
É importante ressaltar, que sempre que for feito uma autenticação, devemos salvar o token com Authentication.saveToken( ) caso queiramos usar a classe do projeto para verificações. Caso não deseje, pode usar a classe Authentication direto da lib.
Exemplo de uso do Login com Google:
@action
Future loginWithGoogle(BuildContext context) async {
try {
loading = true;
final result = await GetIt.I.get<ILoginWithGoogleUsecase>()();
return result.fold(
(l) {
loading = false;
customErrorHelper(context, e: l);
printException("AuthStore.loginWithGoogle", l, l);
return false;
},
(r) async {
loading = false;
//CASO QUEIRA USAR A CLASSE LOCAL AUTHENTICATION PARA VERIFICAÇÕES:
Authentication.saveToken(
(await FirebaseAuth.instance.currentUser?.getIdToken()) ?? "",
);
return true;
},
);
} catch (e, s) {
printException("AuthStore.loginWithGoogle", e, s);
loading = false;
return false;
}
}
Exemplo login com Apple:
@action
Future loginWithApple(BuildContext context) async {
loading = true;
try {
loading = true;
final result = await GetIt.I.get<ILoginWithAppleUsecase>()();
return result.fold(
(l) {
loading = false;
customErrorHelper(context, e: l);
printException("AuthStore.loginWithApple", l, l);
return false;
},
(r) async {
loading = false;
//CASO QUEIRA USAR A CLASSE LOCAL AUTHENTICATION PARA VERIFICAÇÕES:
Authentication.saveToken(
(await FirebaseAuth.instance.currentUser?.getIdToken()) ?? "",
);
return true;
},
);
} catch (e, s) {
printException("AuthStore.loginWIthApple", e, s);
loading = false;
return false;
}
}
Exemplo logout:
@action
Future logout() async {
try {
final result = await GetIt.I.get<ILogoutUsecase>()();
return result.fold(
(l) {
log(l.toString());
log(l.message.toString());
return false;
},
(r) {
return true;
},
);
} catch (e, s) {
printException("logout.AuthStore", e, s);
return false;
}
}
Exemplo de deletar conta:
@action
Future deleteAccount(
BuildContext context, {
required String userId,
}) async {
try {
loading = true;
final result = await GetIt.I.get<IDeleteUserAccountUc>()(
userId: userId,
);
log(result.toString());
await logout();
return true;
} catch (e, s) {
printException("deleteAccount.AuthStore", e, s);
customErrorHelper(context, e: e);
return false;
} finally {
loading = false;
}
}
Last updated