diff --git a/packages/celest/lib/src/auth/auth_provider.dart b/packages/celest/lib/src/auth/auth_provider.dart index 39d60488..bf99d17f 100644 --- a/packages/celest/lib/src/auth/auth_provider.dart +++ b/packages/celest/lib/src/auth/auth_provider.dart @@ -3,14 +3,23 @@ /// /// Currently, Celest supports the following authentication methods: /// - [AuthProvider.email] Email sign-in with OTP codes. +/// - [AuthProvider.sms] SMS sign-in with OTP codes. /// {@endtemplate} sealed class AuthProvider { + /// {@macro celest.auth.auth_provider} const AuthProvider(); /// A provider which enables email sign-in with OTP codes. const factory AuthProvider.email() = _EmailAuthProvider; + + /// A provider which enables SMS sign-in with OTP codes. + const factory AuthProvider.sms() = _SmsAuthProvider; } final class _EmailAuthProvider extends AuthProvider { const _EmailAuthProvider(); } + +final class _SmsAuthProvider extends AuthProvider { + const _SmsAuthProvider(); +} diff --git a/packages/celest_auth/example/celest/auth.dart b/packages/celest_auth/example/celest/auth.dart deleted file mode 100644 index ac57f6a8..00000000 --- a/packages/celest_auth/example/celest/auth.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:celest/celest.dart'; - -const auth = Auth( - providers: [ - AuthProvider.email(), - ], -); diff --git a/packages/celest_auth/example/celest/client/lib/src/auth.dart b/packages/celest_auth/example/celest/client/lib/src/auth.dart index 3685eeac..2237c787 100644 --- a/packages/celest_auth/example/celest/client/lib/src/auth.dart +++ b/packages/celest_auth/example/celest/client/lib/src/auth.dart @@ -19,4 +19,6 @@ extension type CelestAuth._(_$celest.AuthImpl _hub) implements _$celest.Auth { ); _$celest.Email get email => _$celest.Email(_hub); + + _$celest.Sms get sms => _$celest.Sms(_hub); } diff --git a/packages/celest_auth/example/celest/project.dart b/packages/celest_auth/example/celest/project.dart index d8835789..666172a2 100644 --- a/packages/celest_auth/example/celest/project.dart +++ b/packages/celest_auth/example/celest/project.dart @@ -3,3 +3,10 @@ import 'package:celest/celest.dart'; const project = Project( name: 'celest_auth_example', ); + +const auth = Auth( + providers: [ + AuthProvider.email(), + AuthProvider.sms(), + ], +); diff --git a/packages/celest_auth/example/lib/main.dart b/packages/celest_auth/example/lib/main.dart index 23c6c9ee..6c3cf526 100644 --- a/packages/celest_auth/example/lib/main.dart +++ b/packages/celest_auth/example/lib/main.dart @@ -15,13 +15,25 @@ class MainApp extends StatefulWidget { class _MainAppState extends State { final _emailController = TextEditingController(); + final _phoneNumberController = TextEditingController(); final _otpController = TextEditingController(); Future? _request; Future signUp() async { try { - await celest.auth.email.authenticate(email: _emailController.text); + await switch ((_emailController.text, _phoneNumberController.text)) { + (final email, _) when email.isNotEmpty => + celest.auth.email.authenticate( + email: _emailController.text, + ), + (_, final phoneNumber) when phoneNumber.isNotEmpty => + celest.auth.sms.authenticate( + phoneNumber: _phoneNumberController.text, + ), + _ => throw Exception('Email or phone number required'), + }; _emailController.clear(); + _phoneNumberController.clear(); } on Exception catch (e, st) { debugPrint('Error: $e'); debugPrint('Stacktrace: $st'); @@ -78,7 +90,7 @@ class _MainAppState extends State { ], const SizedBox(height: 16), ...switch (state) { - EmailNeedsVerification() => [ + OtpNeedsVerification() => [ TextField( key: const ValueKey('otp'), controller: _otpController, @@ -111,9 +123,21 @@ class _MainAppState extends State { keyboardType: TextInputType.emailAddress, ), const SizedBox(height: 16), + TextField( + key: const ValueKey('phoneNumber'), + controller: _phoneNumberController, + decoration: const InputDecoration( + labelText: 'Phone Number', + ), + autofillHints: const [ + AutofillHints.telephoneNumber, + ], + keyboardType: TextInputType.phone, + ), + const SizedBox(height: 16), TextButton( onPressed: signUp, - child: const Text('Sign In with Email'), + child: const Text('Sign In'), ), ], Authenticated() => [