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

#146 add disable user account #185

Merged
merged 25 commits into from
Sep 15, 2023
Merged

Conversation

haterain0203
Copy link
Collaborator

@haterain0203 haterain0203 commented Sep 7, 2023

Issue

close #146

説明

退会機能を実装する。

  • disableUserAccountRequests コレクションのドキュメントモデルを、firebase_common で定義する。
  • フィールドは下記
    • userId
    • createdAt
  • ログイン済みの場合のみ表示する「退会する」導線を Drawer に設置
  • 押したら AlertDialog を表示して、本当に良いか確認メッセージを表示して、disableUserAccountRequest ドキュメントを作成する
  • Firebase Functions で disableUserAccountRequests コレクションのドキュメント作成をトリガーにして、そのユーザーを disable にする(ただし、TS のドキュメントモデルや Repository クラス、withConverter の定義は行なっていない)
  • 退会処理実行後、AuthService の logout メソッドをコールする
  • 退会処理実行後にユーザーに処理が完了したことをダイアログでユーザーに通知する
  • 退会後にログインしようとした場合、そのアカウントは無効であることをユーザーに通知する

UI

退会処理実行時

Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-09-11.at.22.21.00.mp4

退会処理実行後にログインしようとした時の挙動

Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-09-11.at.22.21.21.mp4

その他

  • 実際にそのユーザーが disabled になって 、もうログインできないことを動作確認済み
  • Firebase Auth の GUI から disabled を解除すると同じユーザーで問題なくログインできることを確認済み

チェックリスト

  • PR の冒頭に関連する Issue 番号を記載しましたか?
  • 本 PR の変更に関して、エディタや IDE で意図しない警告は増えていませんか?(lint 警告やタイポなど)
  • Issue の完了の定義は満たせていますか?
  • 当該 Issue のスレッドで、レビュワーにレビュー依頼をしましたか?

Copy link
Owner

@kosukesaigusa kosukesaigusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View の1箇所以外完璧 of 完璧です!さすがです!!

@@ -180,6 +181,21 @@ class _DrawerChild extends ConsumerWidget {
title: const Text('開発ページへ'),
onTap: () => context.router.pushNamed(DevelopmentItemsPage.location),
),
Visibility(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthDependentBuilder を使ってみてください!(onUnAuthenticated に const SizedBox とかを使うといいとおもいます!)

そこからもらえる userId を使えば、nullable な userIdProvider を使わずに済みます🙆‍♂️

※ あともしそれがないとしても、ログインの有無で見せる見せないを制御するには、Visibility ではなく、単に collection if で良いはずです!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビューありがとうございます!

590db5b
で、AuthDependentBuilder に変更しました!

あと、恥ずかしながら collection if 初めて知りました・・・毎度勉強になります!
ありがとうございます!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後学のためにお伺いしたいのですが、

138行目あたり

if (ref.watch(isSignedInProvider)) ...[
          ListTile(
            leading: const Icon(Icons.person),
            title: Text(ref.watch(userIdProvider)!),
          ),

で、ref.watch(userIdProvider)! がありますが、ここで AuthDependentBuilder を使用していないのは何か理由や意図があるのでしょうか?
if (ref.watch(isSignedInProvider)) で判定しているので、ref.watch(userIdProvider)! で問題ないことは理解しているつもりなのですが、もし使い分けとかがあるので知りたいと思った次第です!

@haterain0203 haterain0203 self-assigned this Sep 8, 2023
Comment on lines +56 to +61
} on FirebaseAuthException catch (e) {
if (e.code == 'user-disabled') {
_appScaffoldMessengerController.showSnackBar('このアカウントは退会済みのため無効です。');
} else {
_appScaffoldMessengerController.showSnackBarByFirebaseException(e);
}
Copy link
Collaborator Author

@haterain0203 haterain0203 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

退会済みのアカウントでログインしようとした場合に、無効であることを通知するようにしてみました!
(冒頭に動画を添付しているので参照ください)

required String userId,
}) async {
await _createDisableUserAccountRequest(userId: userId);
await _authService.signOut();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

退会処理後にログイン状態が保持されてしまうようだったので、サインアウト処理を追加しました。

Comment on lines +44 to +45
Navigator.pop(context);
await _showDisableUserAccountCompletedDialog();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

退会処理が実行された後、退会処理が完了したことを通知するダイアログを追加してみました!
(冒頭のコメントに当該箇所の動画を貼りましたので参照ください)

@haterain0203 haterain0203 changed the title [WIP] #146 add disable user account #146 add disable user account Sep 11, 2023
@haterain0203 haterain0203 merged commit 246994f into main Sep 15, 2023
2 checks passed
@haterain0203 haterain0203 deleted the #146_add_disable_user_account branch September 15, 2023 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

退会機能の実装
2 participants