From 374c2a6d65546fb84e0200607b936acca2dfc533 Mon Sep 17 00:00:00 2001 From: Dillon Nys <24740863+dnys1@users.noreply.github.com> Date: Sat, 9 Mar 2024 12:37:29 -0800 Subject: [PATCH] chore(auth): Clean up (#69) - Rename `email.signIn` to `email.authenticate` to better align with functionality. - Add `celest_auth` as a dependency of `celest` so that it can be imported easily in clientgen. --- packages/celest/pubspec.yaml | 1 + packages/celest/pubspec_overrides.yaml | 9 +++++++++ packages/celest_auth/example/celest/pubspec.yaml | 1 - packages/celest_auth/example/lib/main.dart | 4 ++-- packages/celest_auth/lib/src/flows/email_flow.dart | 10 +++++----- packages/celest_auth/lib/src/state/auth_state.dart | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 packages/celest/pubspec_overrides.yaml diff --git a/packages/celest/pubspec.yaml b/packages/celest/pubspec.yaml index b0079c37..e3aaae81 100644 --- a/packages/celest/pubspec.yaml +++ b/packages/celest/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: async: ^2.11.0 + celest_auth: ^0.3.0 celest_core: ^0.2.0 chunked_stream: ^1.4.2 meta: ^1.9.0 diff --git a/packages/celest/pubspec_overrides.yaml b/packages/celest/pubspec_overrides.yaml new file mode 100644 index 00000000..b18bf1aa --- /dev/null +++ b/packages/celest/pubspec_overrides.yaml @@ -0,0 +1,9 @@ +dependency_overrides: + cedar: + path: ../cedar + celest_auth: + path: ../celest_auth + celest_core: + path: ../celest_core + corks: + path: ../corks diff --git a/packages/celest_auth/example/celest/pubspec.yaml b/packages/celest_auth/example/celest/pubspec.yaml index 7f473bfb..34631b28 100644 --- a/packages/celest_auth/example/celest/pubspec.yaml +++ b/packages/celest_auth/example/celest/pubspec.yaml @@ -7,7 +7,6 @@ environment: dependencies: celest: ^0.2.0 - celest_auth: any celest_core: ^0.2.0 http: ">=0.13.0 <2.0.0" diff --git a/packages/celest_auth/example/lib/main.dart b/packages/celest_auth/example/lib/main.dart index e536d496..4a37d685 100644 --- a/packages/celest_auth/example/lib/main.dart +++ b/packages/celest_auth/example/lib/main.dart @@ -20,7 +20,7 @@ class _MainAppState extends State { Future signUp() async { try { - await celest.auth.email.signIn(email: _emailController.text); + await celest.auth.email.authenticate(email: _emailController.text); _emailController.clear(); } on Exception catch (e, st) { debugPrint('Error: $e'); @@ -92,7 +92,7 @@ class _MainAppState extends State { ), const SizedBox(height: 16), TextButton( - onPressed: () => state.verifyOtp( + onPressed: () => state.verify( _otpController.text, ), child: const Text('Verify OTP'), diff --git a/packages/celest_auth/lib/src/flows/email_flow.dart b/packages/celest_auth/lib/src/flows/email_flow.dart index ad628495..d688e6c1 100644 --- a/packages/celest_auth/lib/src/flows/email_flow.dart +++ b/packages/celest_auth/lib/src/flows/email_flow.dart @@ -13,12 +13,12 @@ extension type Email(AuthImpl _hub) { /// /// OTP codes are valid for 15 minutes and can be resent after 60 seconds /// by calling `resend` on the returned state object. - Future signIn({ + Future authenticate({ required String email, }) async { final flowController = await _hub.requestFlow(); final flow = EmailFlow._(_hub, flowController); - return flow._signIn(email: email); + return flow._authenticate(email: email); } } @@ -30,7 +30,7 @@ final class EmailFlow implements AuthFlow { EmailProtocol get _protocol => _hub.protocol.email; - Future _signIn({ + Future _authenticate({ required String email, }) { return _flowController.capture(() async { @@ -80,8 +80,8 @@ final class _EmailNeedsVerification extends EmailNeedsVerification { } @override - Future verifyOtp(String otp) async { - final authenticated = await _flow._verifyOtp(email: email, otp: otp); + Future verify(String otpCode) async { + final authenticated = await _flow._verifyOtp(email: email, otp: otpCode); return authenticated.user; } diff --git a/packages/celest_auth/lib/src/state/auth_state.dart b/packages/celest_auth/lib/src/state/auth_state.dart index 6f99dced..42e1b077 100644 --- a/packages/celest_auth/lib/src/state/auth_state.dart +++ b/packages/celest_auth/lib/src/state/auth_state.dart @@ -28,7 +28,7 @@ abstract class EmailNeedsVerification extends AuthFlowInProgress { final String email; Future resend(); - Future verifyOtp(String otp); + Future verify(String otpCode); } /// The [user] is authenticated and their identity has been verified.