In Firebase, I could have the following getter and...
# flutter
m
In Firebase, I could have the following getter and set up certain mechanism where my app would automatically logout if the output was null (or stay logged in if the output was of type
User
):
Copy code
dart
Stream<User?> get authChangeStream => _firebaseAuth.authStateChanges();
How can I recreate a similar functionality with Supabase? Currently, I have this:
Copy code
dart
Stream<User?> get authChangeStream {
    return _authService.onAuthStateChange((event, session) => session!.user);
  }
I am getting the following error:
Copy code
A value of type 'GotrueSubscription' can't be returned from the function 'authChangeStream' because it has a return type of 'Stream<User?>'
What should I do to get a
Stream
here?
v
You return the stream subscription, where you can for example close the stream if you are listening to it. You need to create a new stream via
StreamController()
and
add
events to that controller and return the stream from the controller via
controller.stream
.
m
I know that is possible but never had to do it. Firebase made it so simple and I never had to close/cancel it. Regardless, do you have an example of this? Is it worth opening as an issue on `Supabase_flutter`'s github? It would really help if there was native support for it.
Also, what is the difference between
session.user
from my previous message and
_authInstance.currentUser
?
v
I don't know.
I see they don't even use stream intern, but a list of subscribers. Weird pattern 😂
Hopefully they will do it differently in their rework: https://github.com/supabase-community/supabase-dart/issues/109
m
It confuses me too. There are three different ways of getting streams in the database as far as I know. Its so weird.
Yes I read about this a couple days back. Lets hope for the best.
I would gladly help in that if I knew what
gotrue
is lmao
v
what do you mean
m
In the dart library rework. Its open source right? Anyone who knows how to, they can contribute if they want.
There are only like 19 contributors lol
v
m
When I am done with the current project I am making, I'll try to put some time into it.
Gotta pay back to the community somehow
2 Views