Flutter Firebase & DDD Course [9] - Getting the Signed-In User

  Рет қаралды 14,281

Reso Coder

Reso Coder

Күн бұрын

📗 Get the code 👇👇
github.com/Res...
📧 Get Flutter news 📰 and resources:
👉 flutter.education
👨‍💻 Do you write good code? Find out now!
resocoder.com/...
Build command: flutter pub run build_runner watch --delete-conflicting-outputs
We need to have a way to find out whether the user is already signed in or not and also to get the user's ID. We're going to get this data from FirebaseAuth and, of course, hide any mention of Firebase inside the domain layer.
Go to my website for more information, code examples, and articles:
● resocoder.com
Follow me on social media:
● / resocoder
● / resocoder
● / resocoder

Пікірлер: 76
@amaromem1
@amaromem1 4 жыл бұрын
His code is so clean that can protect you from Covid 👌🏻
@ResoCoder
@ResoCoder 4 жыл бұрын
For sure 😂
@JETLAI123
@JETLAI123 4 жыл бұрын
​@@ResoCoder Nice to see your great tutorial again, please keep safe :) BTW don't forget to talk more about TDD video, it will give you double protection from COIVD hahaha
@rizalhadiyansah
@rizalhadiyansah 4 жыл бұрын
Yay! Everytime you upload DDD tutorials, it feels like this is the best day in my life, thank you! 🎉❤
@ResoCoder
@ResoCoder 4 жыл бұрын
You're so welcome!
@Brown-bk4ju
@Brown-bk4ju 4 жыл бұрын
@@ResoCoder Please since Firebase upgrade how to get current user using AuthFacade since _firebaseAuth.currentUser() no longer works
@kondasri1418
@kondasri1418 4 жыл бұрын
@@Brown-bk4ju @override Future getSignedInUser() async => optionOf(_firebaseAuth.currentUser?.toDomain()); try this
@darias.398
@darias.398 3 жыл бұрын
Man, i just wanted to thank you! We have this 4 week project in Uni to create an application. Our group had no idea how to develop an app. Your tutorials saved our project!
@pasindunirmal
@pasindunirmal 4 жыл бұрын
For those following this after the firebase package update which replaced FirebaseUser with User and removed the currentUser() function here's a solution you can use @override Future getSignedInUser() async => optionOf(_firebaseAuth.currentUser?.toDomain()); extension FirebaseUserDomainX on User { CurrentUser toDomain() { return CurrentUser( id: UniqueId.fromUniqueString(uid), ); } } NOTE: I renamed our User class as CurrentUser. If you want you can also use named imports like import 'package:firebase_auth/firebase_auth.dart' as auth; extension FirebaseUserDomainX on auth.User { User toDomain() { return User( id: UniqueId.fromUniqueString(uid), ); } }
@hecher78
@hecher78 Жыл бұрын
Thank you so much for your help!
@DanielSanchezV
@DanielSanchezV 4 жыл бұрын
Wonderful! Every time you upload a video I know there something new to learn! What about spending 10 seconds at the end of the video introducing what is going to be next? So that attendees like me can try to achieve the result by themselves and see your solution at the end. It's a good way to learn faster and better. Let me know! :)
@sumosnow
@sumosnow 4 жыл бұрын
I'm not sure where the VS Code 'vobj' snippet for Value Objects is published online, so here it is in case of use: "Value Object": { "prefix": "vobj", "body": [ "class ${1} extends ValueObject {", " @override", " final Either value;", " factory ${1}(${2} input) {", " return ${1}._(", " // insert validation", " );", " }", " const ${1}._(this.value);", "}" ], "description": "Value Object" },
@lowlydeveloper3693
@lowlydeveloper3693 4 жыл бұрын
Thanks!
@albanr8028
@albanr8028 3 жыл бұрын
Thanks
@kelroar
@kelroar 3 жыл бұрын
Please update the repo. This series is so good you cant let it die like this please. It is really helpful content. 😥
@haidarrmehsen
@haidarrmehsen 4 жыл бұрын
Here is a Like before watching the video :)
@dalestewart
@dalestewart 4 жыл бұрын
Fantastic tutorial. Your code is so logical and clean. True professional Flutter developer. Thanks
@msilvamolina
@msilvamolina 4 жыл бұрын
Awesome 👏 👏 👏 Thanks you for this content. I have a little question... what's is the icon theme for vscode you use?
@h3w45
@h3w45 4 жыл бұрын
in firebase_user_mapper file the code has been changed to this import 'package:firebase_auth/firebase_auth.dart' as firebase; extension FirebaseUserDomainX on firebase.User {} also to get the current user inside firebase_auth_facade file @override Future getSignedInUser() async => optionOf(_firebaseAuth.currentUser?.toDomain());
@prajwalsbelagavi6896
@prajwalsbelagavi6896 4 жыл бұрын
Thank you for the tutorial. Much awaited !
@asimabdalla3344
@asimabdalla3344 4 жыл бұрын
Hit Matt Can you provide us with the value Objects Snippets pls
@tutorialnacional
@tutorialnacional 4 жыл бұрын
Great tutorial series, keep it up!
@rshrewd8809
@rshrewd8809 4 жыл бұрын
Awesome awesome awesome awesome 👍👏
@mikemannox4191
@mikemannox4191 4 жыл бұрын
What is `import 'package:notes_firebase_ddd_course/domain/core/errors.dart';` used for at 17:51?
@THEMithrandir09
@THEMithrandir09 4 жыл бұрын
What's the difference between using Future< T, Unit> vs. Just using Option?
@mdazharuddin4684
@mdazharuddin4684 4 жыл бұрын
I think you mean Either vs Option
@0877adri
@0877adri 4 жыл бұрын
Oh no i watched it till the end. I finally understand why people wait till the whole season is out.
@heduinravell4785
@heduinravell4785 4 жыл бұрын
I needed to add to main.dart: await Firebase.initializeApp(); just above runApp(AppWidget());
@IAmTheMainCharacter
@IAmTheMainCharacter 4 жыл бұрын
reso ddd seems kinda long and only for big project not for medium. It it worth it for small apps?
@ResoCoder
@ResoCoder 4 жыл бұрын
Nope, it's only worth for HUGE apps, if even that. Many concepts are applicable to small apps too but I'd rather not implement value objects at all.
@1b0o0
@1b0o0 4 жыл бұрын
I strongly recommend you to read this short book on the topic. It's pretty straight forward and easy to understand. learning.oreilly.com/library/view/what-is-domain-driven/9781492057802/
@mitchross2852
@mitchross2852 4 жыл бұрын
@resoWhat tutorial series would you recommend for small-medium apps that need to manage auth ?
@patrickkarlsson812
@patrickkarlsson812 4 жыл бұрын
@@ResoCoder Just out of curiosity, how would you do instead of implementing value objects? If you would code a real flutter project, do you mean that you should not go for a non-representable state via value objects and instead just validate in the presentation layer? What architecture are you using in your real projects? Great youtube content by the way :)
@urklegizmo
@urklegizmo 4 жыл бұрын
​ @Reso Coder I would also like to know your thoughts on Patricks question
@xerzes5900
@xerzes5900 4 жыл бұрын
The Long Wait Begins
@heduinravell4785
@heduinravell4785 4 жыл бұрын
Firebase changed FirebaseUser to User, now there is a conflict with internal class User. I had to import 'package:[...]/domain/auth/user.dart' as user; then I used user.User for internal User.. and User for firebase
@AntonDerevyanko
@AntonDerevyanko 4 жыл бұрын
Remember: restart is the best solution in your life :))))
@mqhamdam
@mqhamdam 3 жыл бұрын
Is class User from FirebaseAuth or from the domain layer?
@Flutterdev6391
@Flutterdev6391 4 жыл бұрын
I just want to ask one thing that am I only who understand clearly these series after watching 2-3 times ?
@ResoCoder
@ResoCoder 4 жыл бұрын
You're quite a fast learner actually. I was reading articles about general DDD 5 times in a row at times to grasp the concepts.
@Flutterdev6391
@Flutterdev6391 4 жыл бұрын
@@ResoCoder thanks matt it's give me a lot of confidence😊
@pasindunirmal
@pasindunirmal 4 жыл бұрын
For those looking for 'vobj' snippet add this to user Snippets dart.json file "Value Object Class": { "prefix": "vobj", "body": [ "class ${1} extends ValueObject {", " @override", " final Either value;", "", " factory ${1}(${2} input) {", " return ${1}._(", " //insert validation", " );", " }", "", " const ${1}._(this.value);", "}" ], "description": "Create a Value Object Class" },
@wawrzyn3059
@wawrzyn3059 2 жыл бұрын
thanks!
@lowlydeveloper3693
@lowlydeveloper3693 4 жыл бұрын
Unfortunately, there are major breaking changes starting with firebase_auth 0.18.0 ... currentUser() method, was replaced with the property currentUser, and it no longer returns a Future. So our method getSignedInUser() will no longer work as written... Does anybody have any ideas how to fix this? Or @Reso Coder would you please update the github repository for the project? Much appreciated! Here's more background info: stackoverflow.com/questions/63482162/undefined-class-firebaseuser
@lowlydeveloper3693
@lowlydeveloper3693 4 жыл бұрын
I thought about it, and here's one way to get it working. However, I am new at this. So if there is a more elegant way, please let me know. 🙂 Also note that 'FirebaseUser' type is now gone and replaced with 'User', so we have a name clash with our app 'User' definition. To circumvent it, I used import 'package:firebase_auth/firebase_auth.dart' as fb; Option _maybeUser(String uid) { return (uid == null || uid == '') ? const None() : Some(User( id: UniqueId.fromUniqueString(uid), )); } @override Future getSignedInUser() { final fbUid = fb.FirebaseAuth.instance.currentUser.uid; return Future.value(_maybeUser(fbUid)); }
@lowlydeveloper3693
@lowlydeveloper3693 4 жыл бұрын
Oops, there is a bug above in _getSignedInUser()_ ...I missed the question mark (short-circuit operator) to account for _null_. It should be like so: final fbUid = *fb.FirebaseAuth.instance.currentUser?.uid*
@AdamSmaka
@AdamSmaka 4 жыл бұрын
@@lowlydeveloper3693 Seems good to me, thanks a lot!
@iracemamobile8964
@iracemamobile8964 4 жыл бұрын
The resocoder's github project is not updated.
@binaerverkehr
@binaerverkehr 4 жыл бұрын
Why don't you use the built-in class "UniqueKey"?
@lowlydeveloper3693
@lowlydeveloper3693 3 жыл бұрын
The description on the `currentUser` getter says this: `You should not use this getter to determine the users current state, instead use [authStateChanges], [idTokenChanges] or [userChanges] to subscribe to updates.` I am not clear why it would be a problem to use the `currentUser` as the proxy for the state of signed in user, however, it appears that this code needs to be updated to reflect the current version of FirebaseAuth. Anybody knows, or has any suggestions?
@lowlydeveloper3693
@lowlydeveloper3693 3 жыл бұрын
Here is one idea I thought about using FirebaseAuth recommended [authStateChanges] method (I'm using firebase_auth: ^1.2.0). This should allow us to monitor user authentication state. However, I have not tested it yet to verify that the solution works or not: // In domain layer, IAuthFacade: Stream getSignedInUser(); // Infrastructure implementation in FirebaseAuthFacade: @override Stream getSignedInUser() async* { final userStateStream = _firebaseAuth.authStateChanges(); await for (final user in userStateStream) { yield optionOf(user?.toDomain()); } }
@vaibhavdangayachvd
@vaibhavdangayachvd 4 жыл бұрын
What if we add some more providers then the size of this file would become large. Any way to tackle this? And also when we use verifyPhoneNumber method of firebase it expects some callbacks so how can we express this in a clean way? What I did was that i provided some handler function like handel-failure and handel-success and set the return type to void...is this correct? A verification id is generated when otp is sent should be stored in bloc or in the facade implementation itself?
@APEDUCO
@APEDUCO 4 жыл бұрын
it depends. if you are using verificationId variable in if checks than you should store it in IAuthFacede interface and override it in auth facade in Infrastructure layer. but it would be better keeping in the infrastructure layer and if checking the verification id and returning either AuthFailure or FirebaseUser or unit as matt describes. although keeping it in the infrastructure layer will also help in manually signing in the user using OTP when auto retrieval callback fails in verify phone number method. hope this helps 👍👍
@APEDUCO
@APEDUCO 4 жыл бұрын
phone verification is slightly different than other signing in methods. there are 3 possible outcomes or states ("failed" , "otp not automatically retrieved", "signed in user"). allow user to enter phone number then navigate them so they can enter the received OTP and than manually sign them up using Phone Auth Provider.
@arifikhsanudin9724
@arifikhsanudin9724 4 жыл бұрын
Can i separate auth and notes in features folder like in tdd?
@Brown-bk4ju
@Brown-bk4ju 4 жыл бұрын
Please since Firebase upgrade does anyone know how to get current user using AuthFacade?
@adriano_souza
@adriano_souza 3 жыл бұрын
did you get it?
@LjaDj5XQKey9mSDxh4
@LjaDj5XQKey9mSDxh4 4 жыл бұрын
I can't find the extension for the snippets 'fdatac' and 'ptf' :/
@Brown-bk4ju
@Brown-bk4ju 4 жыл бұрын
its a code snippet he created and added to dart.json in VS Code
@iqboladahamjonov9835
@iqboladahamjonov9835 3 жыл бұрын
I would recomment not to call User the class which is defined in damain auth folder, because dart will confuse it the User class which is defined in Firebase auth package.
@NimoArts
@NimoArts 3 жыл бұрын
I would recommend using import '...' as ...; so you are not forced to rename User class just because firebase_auth(or any other dependency) has a User class as well
@arifikhsanudin9724
@arifikhsanudin9724 4 жыл бұрын
where is the snippet vobj?
@mahmudulhasan4979
@mahmudulhasan4979 3 жыл бұрын
in firebase 1.4.1 this code Future getSignedInUser() async => optionOf(_firebaseAuth.currentUser!.toDomain()); said that can The argument type 'User' can't be assigned to the parameter type 'User?' how can solve this any one have any clue??
@biplabdutta
@biplabdutta 3 жыл бұрын
_firebaseAuth.currentUser?.toDomain()
@mahmudulhasan4979
@mahmudulhasan4979 3 жыл бұрын
@@biplabdutta thanks but currentUser data type is User? so toDomain() is not assigned with currentUser because toDomain() data type is User. that's why ist saying type 'User' can't be assigned to the parameter type 'User?'
@mahmudulhasan4979
@mahmudulhasan4979 3 жыл бұрын
@Flutter optionOf(_firebaseAuth.currentUser?.toDomain());
@AdamSmaka
@AdamSmaka 4 жыл бұрын
After updating firebase to newer version the code needs to be updated too. This is how I handled it, correct me if it's wrong. import 'package:firebase_auth/firebase_auth.dart' as firebase; @override Future getSignedInUser() { return Future.value(optionOf(_firebaseAuth.currentUser?.toDomain())); } __ import 'package:firebase_auth/firebase_auth.dart' as firebase; ... extension UserDomainX on firebase.User { User toDomain() { return User(id: UniqueId.fromUniqueString(uid)); } }
@abdoselim1990
@abdoselim1990 4 жыл бұрын
firebase documentation tells u specifically not to do that : [currentUser] "Returns the current [User] if they are currently signed-in, or `null` if" "You should not use this getter to determine the users current state," "instead use [authStateChanges], [idTokenChanges] or [userChanges] to" "subscribe to updates." i hope that clears it up a bit, if u get to a solution let me know. im stuck here as well
@AdeYudysTriawan
@AdeYudysTriawan 4 жыл бұрын
hai matt, i have a question..if i fetch data from api which is not supported real time update like firebase, do i need use stream type like u do with notes in finished project or just future? thanks
@APEDUCO
@APEDUCO 4 жыл бұрын
use Future instead for non realtime database services. You can call the fetching function periodically or onRefresh callbacks to mimic the realtime sort of thing kind of 🤞.
@vaibhavdangayachvd
@vaibhavdangayachvd 4 жыл бұрын
@@APEDUCO I think we can use streams and in on-refresh we can send loaded data as stream
@APEDUCO
@APEDUCO 4 жыл бұрын
@@vaibhavdangayachvd you can use streams that way and always remember to update the data whenever a change occurs. 👍 you can take a look at ticker example in the bloclibrary.dev/#/fluttertimertutorial
@parthpatel9757
@parthpatel9757 4 жыл бұрын
Anyone find vobj snippet?
@ilg8410
@ilg8410 2 жыл бұрын
25:00
@jeromestsauver
@jeromestsauver 4 жыл бұрын
I always see 1 downvote on each of these - same person? lol
Flutter Firebase & DDD Course [7] - Injectable & Linting
26:41
Reso Coder
Рет қаралды 19 М.
Squid game
00:17
Giuseppe Barbuto
Рет қаралды 37 МЛН
The perfect snowball 😳❄️ (via @vidough/TT)
00:31
SportsNation
Рет қаралды 77 МЛН
Flutter Firebase & DDD Course [8] - Sign-In Form UI
42:37
Reso Coder
Рет қаралды 22 М.
Flutter Firebase & DDD Course [6] - Firebase Auth Setup & Facade
44:52
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 858 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Rant: Entity systems and the Rust borrow checker ... or something.
1:01:51
5 deadly Rust anti-patterns to avoid
13:25
Let's Get Rusty
Рет қаралды 41 М.
C can do this too and it's faster than Python
2:09:48
Tsoding Daily
Рет қаралды 22 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 363 М.