me method

Future<FFXUser> me()

Fetches the current user from the server and updates currentUser and the persisted snapshot.

Implementation

Future<FFXUser> me() async {
  final epoch = _sessionEpoch;
  final res = await _http.request('GET', '/v1/auth/me');
  if (epoch != _sessionEpoch) {
    // Signed out or switched accounts while this request was in flight:
    // the response describes a previous identity. Discard it — no
    // assignment, no persistence, no auth-state event.
    throw FFXAuthenticationError({
      'code': 'sessionExpired',
      'detail': 'The session changed while the request was in flight.',
      'fix': 'Read auth.currentUser for the current identity.',
      'retry': 'never',
    }, 0);
  }
  _user = FFXUser.fromJson((res.body['data'] as Map).cast<String, Object?>());
  final session = _session;
  if (session != null) {
    _session = session.withUser(_user!.toJson());
    await _persist(epoch);
  }
  _assertEpoch(epoch);
  _emit();
  return _user!;
}