Skip to content

Commit

Permalink
chore(auth): Clean up (#69)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
dnys1 authored Mar 9, 2024
1 parent 6420c32 commit 374c2a6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/celest/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/celest/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependency_overrides:
cedar:
path: ../cedar
celest_auth:
path: ../celest_auth
celest_core:
path: ../celest_core
corks:
path: ../corks
1 change: 0 additions & 1 deletion packages/celest_auth/example/celest/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions packages/celest_auth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _MainAppState extends State<MainApp> {

Future<void> 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');
Expand Down Expand Up @@ -92,7 +92,7 @@ class _MainAppState extends State<MainApp> {
),
const SizedBox(height: 16),
TextButton(
onPressed: () => state.verifyOtp(
onPressed: () => state.verify(
_otpController.text,
),
child: const Text('Verify OTP'),
Expand Down
10 changes: 5 additions & 5 deletions packages/celest_auth/lib/src/flows/email_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmailNeedsVerification> signIn({
Future<EmailNeedsVerification> 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);
}
}

Expand All @@ -30,7 +30,7 @@ final class EmailFlow implements AuthFlow {

EmailProtocol get _protocol => _hub.protocol.email;

Future<EmailNeedsVerification> _signIn({
Future<EmailNeedsVerification> _authenticate({
required String email,
}) {
return _flowController.capture(() async {
Expand Down Expand Up @@ -80,8 +80,8 @@ final class _EmailNeedsVerification extends EmailNeedsVerification {
}

@override
Future<User> verifyOtp(String otp) async {
final authenticated = await _flow._verifyOtp(email: email, otp: otp);
Future<User> verify(String otpCode) async {
final authenticated = await _flow._verifyOtp(email: email, otp: otpCode);
return authenticated.user;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/celest_auth/lib/src/state/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class EmailNeedsVerification extends AuthFlowInProgress {
final String email;

Future<void> resend();
Future<User> verifyOtp(String otp);
Future<User> verify(String otpCode);
}

/// The [user] is authenticated and their identity has been verified.
Expand Down

0 comments on commit 374c2a6

Please sign in to comment.