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

build: Update lint package dependencies and integrate custom linting across packages #111

Merged
merged 1 commit into from
Dec 2, 2024
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
3 changes: 3 additions & 0 deletions .cspell/flutter-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Podfile
postbootstrap
postclean
pubspec
Reauthenticates
reauthenticating
reauthentication
Reorderable
revenuecat
riverpod
Expand Down
6 changes: 2 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ dependencies:
dev_dependencies:
altfire_lints:
path: ../packages/altfire_lints
altive_lints: ^1.10.0
custom_lint: ^0.6.4
altive_lints: ^1.16.0
custom_lint: ^0.7.0
flutter_test:
sdk: flutter

flutter:
3 changes: 3 additions & 0 deletions packages/altfire_authenticator/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include: package:altive_lints/altive_lints.yaml
analyzer:
plugins:
- custom_lint
2 changes: 1 addition & 1 deletion packages/altfire_authenticator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
sdk: flutter

dev_dependencies:
altive_lints: ^1.10.0
altive_lints: ^1.16.0
flutter_test:
sdk: flutter

Expand Down
26 changes: 20 additions & 6 deletions packages/altfire_authenticator/lib/src/apple_authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,52 @@ import 'package:flutter/foundation.dart';
import '../altfire_authenticator.dart';
import 'authenticatable.dart';

/// AppleAuthenticator is a class that implements the Authenticatable interface
/// to provide authentication using Apple Sign-In with Firebase.
///
/// This class handles the authentication process for Apple Sign-In, including
/// signing in, reauthenticating, linking, and unlinking the Apple provider.
///
/// It uses the FirebaseAuth instance to perform authentication operations.
///
/// Example usage:
/// ```dart
/// final appleAuthenticator = AppleAuthenticator(FirebaseAuth.instance);
/// final userCredential = await appleAuthenticator.signIn();
/// ```
class AppleAuthenticator implements Authenticatable {
/// Creates a new instance of AppleAuthenticator with
/// the provided FirebaseAuth instance.
AppleAuthenticator(this._auth);

final FirebaseAuth _auth;

final authProvider = AppleAuthProvider();
final _authProvider = AppleAuthProvider();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it a private variable to match the other XxxAuthenticator, as it seemed to be used only internally!


User get _user => _auth.currentUser!;

/// 既にAppleでサインイン済みなら`true`
@override
bool get alreadySigned => _auth.currentUser?.hasAppleSigning ?? false;

@override
Future<UserCredential> signIn([AuthCredential? credential]) async {
if (kIsWeb) {
final userCredential = await _auth.signInWithPopup(authProvider);
final userCredential = await _auth.signInWithPopup(_authProvider);
return userCredential;
} else {
final userCredential = await _auth.signInWithProvider(authProvider);
final userCredential = await _auth.signInWithProvider(_authProvider);
return userCredential;
}
}

@override
Future<UserCredential> reauthenticate([AuthCredential? credential]) async {
return _auth.currentUser!.reauthenticateWithProvider(authProvider);
return _auth.currentUser!.reauthenticateWithProvider(_authProvider);
}

@override
Future<UserCredential> link([AuthCredential? credential]) async {
return _user.linkWithProvider(authProvider);
return _user.linkWithProvider(_authProvider);
}

@override
Expand Down
14 changes: 14 additions & 0 deletions packages/altfire_authenticator/lib/src/auth_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,44 @@ sealed class AuthException implements Exception {
}
}

/// Error class indicating that authentication was cancelled.
class AuthCancelled implements AuthException {
/// Creates a new instance of AuthCancelled.
const AuthCancelled();
}

/// Error class indicating that recent sign-in is required.
class AuthRequiresRecentSignIn implements AuthException {
/// Creates a new instance of AuthRequiresRecentSignIn.
const AuthRequiresRecentSignIn();
}

/// Error class indicating that the phone number is invalid.
class AuthInvalidPhoneNumber implements AuthException {
/// Creates a new instance of AuthInvalidPhoneNumber.
const AuthInvalidPhoneNumber();
}

/// Error class indicating that the credential is already in use.
class AuthCredentialAlreadyInUse implements AuthException {
/// Creates a new instance of AuthCredentialAlreadyInUse.
const AuthCredentialAlreadyInUse();
}

/// Error class indicating that the network request failed.
class AuthFailedNetworkRequest implements AuthException {
/// Creates a new instance of AuthFailedNetworkRequest.
const AuthFailedNetworkRequest();
}

/// Error class indicating an undefined error.
class AuthUndefinedError implements AuthException {
/// Creates a new instance of AuthUndefinedError.
const AuthUndefinedError();
}

/// Error class indicating that sign-in is required.
class AuthRequiresSignIn implements AuthException {
/// Creates a new instance of AuthRequiresSignIn.
const AuthRequiresSignIn();
}
34 changes: 20 additions & 14 deletions packages/altfire_authenticator/lib/src/authenticatable.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import 'package:firebase_auth/firebase_auth.dart';

/// Interface for authenticatable classes.
///
/// This interface defines the methods required for authentication operations
/// such as sign-in, reauthentication, linking, and unlinking.
///
/// Implementing classes should provide concrete implementations for methods.
abstract class Authenticatable {
/// すでにサインイン済みかどうか。
/// Whether the user is already signed in.
bool get alreadySigned;

/// サインイン。
/// Signs in the user.
///
/// 電話番号認証ではサインイン処理が2STEPに分かれており、
/// [AuthCredential]を外から渡す必要があるため、
/// オプショナル引数として[AuthCredential]を受け取る形にしている。
/// For phone number authentication, the sign-in process is divided into
/// two steps, and an [AuthCredential] needs to be provided from outside.
/// Therefore, it is accepted as an optional argument.
Future<UserCredential> signIn([AuthCredential? credential]);

/// 再認証する。
/// Reauthenticates the user.
///
/// 電話番号認証ではサインイン処理が2STEPに分かれており、
/// [AuthCredential]を外から渡す必要があるため、
/// オプショナル引数として[AuthCredential]を受け取る形にしている。
/// For phone number authentication, the reauthentication process is divided
/// into two steps, and an [AuthCredential] needs to be provided from outside.
/// Therefore, it is accepted as an optional argument.
Future<UserCredential> reauthenticate([AuthCredential? credential]);

/// ユーザーにAppleを紐付ける。
/// Links the user with an Apple account.
///
/// 電話番号認証ではサインイン処理が2STEPに分かれており、
/// [AuthCredential]を外から渡す必要があるため、
/// オプショナル引数として[AuthCredential]を受け取る形にしている。
/// For phone number authentication, the linking process is divided into
/// two steps, and an [AuthCredential] needs to be provided from outside.
/// Therefore, it is accepted as an optional argument.
Future<UserCredential> link([AuthCredential? credential]);

/// Apple IDをリンク解除。
/// Unlinks the user's Apple ID.
Future<User> unlink();
}
3 changes: 2 additions & 1 deletion packages/altfire_authenticator/lib/src/authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'phone_authenticator.dart';

/// [Authenticator] is a wrapper class for [FirebaseAuth].
class Authenticator {
/// Creates a new instance of [Authenticator].
Authenticator({
FirebaseAuth? auth,
AppleAuthenticator? appleAuthenticator,
Expand Down Expand Up @@ -141,7 +142,7 @@ class Authenticator {
} else if (_appleAuth.alreadySigned) {
return _appleAuth.reauthenticate();
} else {
throw UnimplementedError('未対応のSigningMethodがあります。');
throw UnimplementedError('Reauthentication is not implemented.');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ import 'package:google_sign_in/google_sign_in.dart';
import '../altfire_authenticator.dart';
import 'authenticatable.dart';

/// GoogleAuthenticator is a class that implements the Authenticatable interface
/// to provide authentication using Google Sign-In with Firebase.
///
/// This class handles the authentication process for Google Sign-In, including
/// signing in, reauthenticating, linking, and unlinking the Google provider.
///
/// It uses the FirebaseAuth instance to perform authentication operations.
///
/// Example usage:
/// ```dart
/// final googleAuthenticator = GoogleAuthenticator(FirebaseAuth.instance);
/// final userCredential = await googleAuthenticator.signIn();
/// ```
class GoogleAuthenticator implements Authenticatable {
/// Creates a new instance of GoogleAuthenticator with
GoogleAuthenticator(this._auth);

final FirebaseAuth _auth;

final GoogleSignIn _googleSignIn = GoogleSignIn();
final _googleSignIn = GoogleSignIn();

User get _user => _auth.currentUser!;

Expand Down
37 changes: 31 additions & 6 deletions packages/altfire_authenticator/lib/src/phone_authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,47 @@ import 'package:firebase_auth/firebase_auth.dart';
import '../altfire_authenticator.dart';
import 'authenticatable.dart';

/// PhoneAuthenticator is a class that implements the Authenticatable interface
/// to provide authentication using phone number verification with Firebase.
///
/// This class handles the authentication process for phone number verification,
/// including verifying the phone number, signing in, reauthenticating, linking,
/// and unlinking the phone provider.
///
/// It uses the FirebaseAuth instance to perform authentication operations.
///
/// Example usage:
/// ```dart
/// final phoneAuthenticator = PhoneAuthenticator(FirebaseAuth.instance);
/// await phoneAuthenticator.verifyPhoneNumber(
/// phoneNumber: '+1234567890',
/// verificationCompleted: (credential) async {
/// final userCredential = await phoneAuthenticator.signIn(credential);
/// },
/// verificationFailed: (exception) {
/// print('Failed to verify phone number: $exception');
/// },
/// codeSent: (verificationId, forceResendingToken) {
/// print('Verification code sent to phone number');
/// },
/// codeAutoRetrievalTimeout: (verificationId) {
/// print('Verification code auto-retrieval timed out');
/// },
/// );
/// ```
class PhoneAuthenticator implements Authenticatable {
/// Creates a new instance of PhoneAuthenticator with
/// the provided FirebaseAuth instance.
PhoneAuthenticator(this._auth);

final FirebaseAuth _auth;

User get _user => _auth.currentUser!;

/// 既に電話番号でサインイン済みなら`true`
@override
bool get alreadySigned => _auth.currentUser?.hasPhoneSigning ?? false;

/// 電話番号を検証し認証コードを送信する。
/// Verifies the phone number and sends a verification code.
Future<void> verifyPhoneNumber({
required String phoneNumber,
required void Function(PhoneAuthCredential credential)
Expand All @@ -33,7 +62,6 @@ class PhoneAuthenticator implements Authenticatable {
);
}

/// SMS認証コードを使ってサインインする。
@override
Future<UserCredential> signIn([AuthCredential? credential]) async {
if (credential == null) {
Expand All @@ -42,7 +70,6 @@ class PhoneAuthenticator implements Authenticatable {
return _auth.signInWithCredential(credential);
}

/// 電話番号認証で再認証する。
@override
Future<UserCredential> reauthenticate([AuthCredential? credential]) {
if (credential == null) {
Expand All @@ -51,7 +78,6 @@ class PhoneAuthenticator implements Authenticatable {
return _user.reauthenticateWithCredential(credential);
}

/// 電話番号認証を連携する。
@override
Future<UserCredential> link([AuthCredential? credential]) {
if (credential == null) {
Expand All @@ -60,7 +86,6 @@ class PhoneAuthenticator implements Authenticatable {
return _user.linkWithCredential(credential);
}

/// 電話番号認証の連携を解除する。
@override
Future<User> unlink() {
return _user.unlink(SigningMethod.phone.providerId);
Expand Down
7 changes: 7 additions & 0 deletions packages/altfire_authenticator/lib/src/signing_method.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import 'package:firebase_auth/firebase_auth.dart';

/// Enum class for identifying the method of authentication.
enum SigningMethod {
/// Apple authentication.
apple,

/// Google authentication.
google,

/// Phone number authentication.
phone,
;

/// Returns the provider ID corresponding to the authentication method.
String get providerId {
switch (this) {
case SigningMethod.apple:
Expand Down
6 changes: 6 additions & 0 deletions packages/altfire_authenticator/lib/src/user_extension.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import '../altfire_authenticator.dart';

/// Extension methods for the [User] class.
extension UserExtension on User {
/// Whether the user has a Google account.
bool get hasGoogleSigning => providerData.any(
(userInfo) => userInfo.providerId == SigningMethod.google.providerId,
);

/// Whether the user has an Apple account.
bool get hasAppleSigning => providerData.any(
(userInfo) => userInfo.providerId == SigningMethod.apple.providerId,
);

/// Whether the user has a phone number.
bool get hasPhoneSigning => providerData.any(
(userInfo) => userInfo.providerId == SigningMethod.phone.providerId,
);
Expand Down
3 changes: 2 additions & 1 deletion packages/altfire_authenticator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
google_sign_in: ^6.2.1

dev_dependencies:
altive_lints: ^1.10.0
altive_lints: ^1.16.0
custom_lint: ^0.7.0
flutter_test:
sdk: flutter
3 changes: 3 additions & 0 deletions packages/altfire_configurator/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include: package:altive_lints/altive_lints.yaml
analyzer:
plugins:
- custom_lint
4 changes: 2 additions & 2 deletions packages/altfire_configurator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dependencies:
dev_dependencies:
altfire_lints:
path: ../../altfire_lints
altive_lints: ^1.10.0
custom_lint: ^0.6.4
altive_lints: ^1.16.0
custom_lint: ^0.7.0

flutter:
uses-material-design: true
1 change: 1 addition & 0 deletions packages/altfire_configurator/lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
/// A class that holds the value of a parameter fetched from a remote.
/// It also provides a Stream of updated parameter information.
class Config<T> {
/// Creates a new instance of [Config].
Config({
required T value,
required StreamSubscription<void>? subscription,
Expand Down
Loading