Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ログイン処理周りのanalyticsを追加。currentUserが無い場合はFirebaseAuthのinitializeを待つ #559

Merged
merged 5 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/domain/root/root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ class RootState extends State<Root> {

await forceUpdateTrace.stop();

return packageVersion
final forceUpdate = packageVersion
.isLessThan(Version.parse(config.minimumSupportedAppVersion));
if (forceUpdate) {
analytics.logEvent(
name: "screen_type_force_update",
parameters: {
"package_version": packageVersion.toString(),
"minimum_app_version": config.minimumSupportedAppVersion,
},
);
}
return forceUpdate;
}

Future<FirebaseAuth.User> _signIn() async {
Expand All @@ -139,13 +149,16 @@ class RootState extends State<Root> {
bool? didEndInitialSetting =
sharedPreferences.getBool(BoolKey.didEndInitialSetting);
if (didEndInitialSetting == null) {
analytics.logEvent(name: "did_end_i_s_is_null");
return ScreenType.initialSetting;
}
if (!didEndInitialSetting) {
analytics.logEvent(name: "did_end_i_s_is_false");
return ScreenType.initialSetting;
}

return screenType = ScreenType.home;
analytics.logEvent(name: "screen_type_is_home");
return ScreenType.home;
}

Future<User> _mutateUserWithLaunchInfoAnd(
Expand All @@ -165,9 +178,14 @@ class RootState extends State<Root> {
final userService = UserService(DatabaseConnection(firebaseUser.uid));
await userService.deleteSettings();
await userService.setFlutterMigrationFlag();
analytics.logEvent(
name: "user_is_not_migrated_flutter",
parameters: {"uid": firebaseUser.uid});
return ScreenType.initialSetting;
} else if (user.setting == null) {
return screenType = ScreenType.initialSetting;
analytics.logEvent(
name: "uset_setting_is_null", parameters: {"uid": firebaseUser.uid});
return ScreenType.initialSetting;
}
return null;
}
Expand Down
30 changes: 27 additions & 3 deletions lib/service/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Stream<User?> _userAuthStateChanges() {
}

// Obtain the latest users form FirebaseAuth.
// If it is not exists, return result of signin anonymous;
// If it is not exists:
// -> wait userAuthStateChanges stream complete that firebase auth setup complete:
// -> return result of signin anonymous;
Future<User> cachedUserOrSignInAnonymously() async {
analytics.logEvent(name: "call_sign_in");
final currentUser = FirebaseAuth.instance.currentUser;
Expand All @@ -53,7 +55,7 @@ Future<User> cachedUserOrSignInAnonymously() async {

if (currentUser != null) {
analytics.logEvent(
name: "current_user_exists",
name: "cached_current_user_exists",
parameters: _logginParameters(currentUser));

final sharedPreferences = await SharedPreferences.getInstance();
Expand All @@ -64,8 +66,30 @@ Future<User> cachedUserOrSignInAnonymously() async {

return currentUser;
} else {
final anonymousUser = await FirebaseAuth.instance.signInAnonymously();
analytics.logEvent(name: "cached_current_user_not_exists");

// keep until FirebaseAuth.instance user state updated
final obtainLatestChangedOptionalUserState = Future<User?>(() {
final completer = Completer<User?>();

StreamSubscription<User?>? subscription;
subscription = _userAuthStateChanges().listen((firebaseUser) {
completer.complete(firebaseUser);
subscription?.cancel();
});
return completer.future;
});

final obtainedUser = await obtainLatestChangedOptionalUserState;
if (obtainedUser != null) {
analytics.logEvent(
name: "obtained_current_user_exists",
parameters: _logginParameters(obtainedUser),
);
return obtainedUser;
}

final anonymousUser = await FirebaseAuth.instance.signInAnonymously();
analytics.logEvent(
name: "signin_anonymously",
parameters: _logginParameters(anonymousUser.user));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:pilll/database/batch.dart';
import 'package:pilll/domain/initial_setting/initial_setting_state.codegen.dart';
import 'package:pilll/domain/initial_setting/initial_setting_store.dart';
import 'package:pilll/entity/pill_sheet.codegen.dart';
import 'package:pilll/entity/pill_sheet_group.codegen.dart';
Expand Down