title: Riverpod: Is there a correct way to read a StreamProvider within another StreamProvider?
body: <p>I have been attempting to create streams to Firestore documents using the <em>uid</em> obtained from my auth <code>Provider</code>:</p>
  <pre><code>class AuthService {
    ...
  
    static final provider = StreamProvider.autoDispose((ref) =&gt; FirebaseAuth.instance.onAuthStateChanged);
    ...
  }
  </code></pre>
  <p>However, I am struggling to actually create a <code>StreamProvider</code> dependent on the value from the auth <code>Provider</code>.</p>
  <pre><code>class User {
    ...
    static final provider = StreamProvider((ref) {
      final stream = ref.read(AuthService.provider);
      // Returns AsyncValue&lt;Stream&lt;User&gt;&gt; instead of desired AsyncValue&lt;User&gt;
      return stream.map((auth) =&gt; Service.user.stream(auth.uid));
    });
    ...
  }
  </code></pre>
  <p>I also tried using <code>Computed</code> to return the <em>uid</em> or the stream itself but you cannot read a <code>Computed</code> from a <code>Provider</code> (which makes sense in retrospect).</p>
  <p><a href="https://stackoverflow.com/questions/57688304/how-to-setup-streamprovider-which-take-a-param-value-from-another-streamprovider">This question</a> is the most relevant on this topic but it is dealing with Provider, not Riverpod.</p>
  <p>P.S. Can a Riverpod tag be created?</p>
  <p>Edit:</p>
  <p>The answer isn't working quite right. The <code>await for loop</code> is only ever triggering once, whereas a listener catches all events.</p>
  <pre><code>static final provider = StreamProvider((ref) async* {
    final stream = ref.read(AuthService.provider);
    print('userProvider init');
  
    stream.listen((auth) {
      print('LISTENED: ${auth?.uid}');
    });
  
    await for (final auth in stream) {
      print('uid: ${auth?.uid}');
      yield* Service.user.stream(auth?.uid);
    }
  });
  </code></pre>
  <p>This code yields the following on login:</p>
  <pre><code>userProvider init
  LISTENED: &lt;redacted UID&gt;
  uid: &lt;redacted UID&gt;
  </code></pre>
  <p>And then on logout:</p>
  <p><code>LISTENED: null</code></p>
  <p>Where I would expect to see <code>uid: null</code> as well, which would update the stream, but upon any more auth events, only the listener is triggered and no events are caught by the <code>await for loop</code>.</p>
  <p>Interestingly, using the flutter inspector, the value emitted by the auth provider never changes, either:</p>
  <p><code>AutoDisposeStreamProvider&lt;FirebaseUser&gt;#95f11: AsyncValue&lt;FirebaseUser&gt;.data(value: FirebaseUser(Instance of 'PlatformUser'))</code></p>
  <p>persists through login/logout events, which could explain this behavior, but I am not sure what to do to fix it.</p>
  <p>Any ideas? I have been stuck on this for a while and can't correct the issue.</p>