mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can sign out of the application
This commit is contained in:
		@@ -10,7 +10,6 @@ import 'package:shared_preferences/shared_preferences.dart';
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class AccountCredentialsHelper {
 | 
			
		||||
 | 
			
		||||
  /// Checkout whether current user is signed in or not
 | 
			
		||||
  Future<bool> signedIn() async {
 | 
			
		||||
    return await get() != null;
 | 
			
		||||
@@ -19,21 +18,20 @@ class AccountCredentialsHelper {
 | 
			
		||||
  /// Set new login tokens
 | 
			
		||||
  Future<void> set(LoginTokens tokens) async {
 | 
			
		||||
    SharedPreferences prefs = await SharedPreferences.getInstance();
 | 
			
		||||
    await prefs.setString("login_tokens", tokens.toString());
 | 
			
		||||
    await prefs.setString(
 | 
			
		||||
        "login_tokens", tokens == null ? "null" : tokens.toString());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Get current [LoginTokens]. Returns null if none or in case of failure
 | 
			
		||||
  Future<LoginTokens> get() async {
 | 
			
		||||
    try {
 | 
			
		||||
 | 
			
		||||
      SharedPreferences prefs = await SharedPreferences.getInstance();
 | 
			
		||||
      final string = prefs.getString("login_tokens");
 | 
			
		||||
      if(string == null) return null;
 | 
			
		||||
      if (string == null || string == "null") return null;
 | 
			
		||||
      return LoginTokens.fromJSON(jsonDecode(string));
 | 
			
		||||
 | 
			
		||||
    } on Exception catch(e){
 | 
			
		||||
    } on Exception catch (e) {
 | 
			
		||||
      print(e.toString());
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -38,4 +38,10 @@ class AccountHelper {
 | 
			
		||||
 | 
			
		||||
    return AuthResult.SUCCESS;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Sign out user
 | 
			
		||||
  Future<void> signOut() async {
 | 
			
		||||
    await AccountCredentialsHelper().set(null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user