1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Can sign out of the application

This commit is contained in:
2019-04-23 11:48:49 +02:00
parent 07d668eb59
commit d10df9dd7a
5 changed files with 108 additions and 8 deletions

View File

@ -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;
}
}
}
}

View File

@ -38,4 +38,10 @@ class AccountHelper {
return AuthResult.SUCCESS;
}
/// Sign out user
Future<void> signOut() async {
await AccountCredentialsHelper().set(null);
}
}