-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from crunchloop/injectable
Add dependency injection for auth
- Loading branch information
Showing
11 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'user.g.dart'; | ||
|
||
@JsonSerializable() | ||
class User extends Equatable { | ||
final String id; | ||
final String? email; | ||
final String? username; | ||
|
||
const User({required this.id, required this.email, required this.username}); | ||
|
||
@override | ||
List<Object?> get props => [id, email, username]; | ||
|
||
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$UserToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:auth/auth.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import '../models/user.dart'; | ||
|
||
@Injectable() | ||
class AuthFacade { | ||
Future<void> signIn({ | ||
required String email, | ||
required String password, | ||
}) { | ||
return Auth.signInWithEmailAndPassword(email: email, password: password); | ||
} | ||
|
||
Future<void> register( | ||
{required String username, | ||
required String email, | ||
required String password}) { | ||
return Auth.createUserWithEmailAndPassword( | ||
email: email, password: password); | ||
} | ||
|
||
User? getUser() { | ||
final user = Auth.currentUser; | ||
|
||
return user == null | ||
? null | ||
: User(id: user.uid, email: user.email, username: user.displayName); | ||
} | ||
|
||
Future<void> signOut() { | ||
return Auth.signOut(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:auth/auth.dart'; | ||
|
||
class FirebaseAuthService { | ||
static Future<FirebaseAuthService> init() async { | ||
await Auth.initialize(); | ||
|
||
return FirebaseAuthService(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters