Code on the Rocks
Code on the Rocks

Reputation: 17566

How do you check if an at sign is "logged in"?

I'm working with the privacy-focused @platform created by the At Company and I'm wondering what's the fastest method for determining if a user is "logged in". To accomplish this with Firebase Auth, for example, you would simply check if the current user is null:

final loggedIn = FirebaseAuth.instance.currentUser != null;

Is there a similar check I could perform with the @platform?

My current approach is to check for the first at sign in the key chain and verify that it's not null. I feel like I'm missing a check to see if this at sign is actually "authenticated".

 String? loggedInAtsign = await atProtocolService.keyChainManager.getAtSign();
 bool loggedIn = loggedInAtSign != null;

Upvotes: 0

Views: 44

Answers (1)

minnu
minnu

Reputation: 15

If you are trying to check it when you reopen the app. Then yes, we have a way to check it. You can go with

String? _currentAtSign;
/// If you have more than 1 @sign in the app.
/// This will return a map like
/// ```
/// <String, bool?>{
///   '@mangotangostable' : true,
///   '@minnu💚' : false,
/// }
/// ```

Map<String, bool?> atSigns = await atProtocolService.keyChainManager.getAtsignsWithStatus();
if (atSigns.isNotEmpty) {
    _currentAtSign = atSigns.keys.firstWhere((String key) => atSigns[key]!);
}
print(_currentAtSign); // @mangotangostable

But your approach will also work(Simple and easy).

Upvotes: 0

Related Questions