paradigm shift
This commit is contained in:
@@ -21,6 +21,7 @@ class AuthAPI extends ChangeNotifier {
|
||||
late final appwrite.Account account;
|
||||
|
||||
late models.User _currentUser;
|
||||
late models.Session _currentSession;
|
||||
|
||||
AuthStatus _status = AuthStatus.UNINITIALIZED;
|
||||
|
||||
@@ -32,11 +33,16 @@ class AuthAPI extends ChangeNotifier {
|
||||
AuthStatus get status => _status;
|
||||
String? get username => _currentUser.name;
|
||||
String? get email => _currentUser.email;
|
||||
String? get userID => _currentUser.$id;
|
||||
String? get userID {
|
||||
try {
|
||||
return _currentUser.$id;
|
||||
} catch (e) {
|
||||
return _currentSession.$id;
|
||||
}
|
||||
}
|
||||
|
||||
AuthAPI() {
|
||||
AuthAPI({bool autoLoad = true}) {
|
||||
init();
|
||||
loadUser();
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -45,6 +51,29 @@ class AuthAPI extends ChangeNotifier {
|
||||
.setProject(ApiConstants.APPWRITE_PROJECT_ID)
|
||||
.setSelfSigned();
|
||||
account = appwrite.Account(client);
|
||||
try {
|
||||
account.get().then((value) {
|
||||
_currentUser = value;
|
||||
_status = AuthStatus.AUTHENTICATED;
|
||||
print("Auto loaded user: ${_currentUser.name}");
|
||||
print("Auth status: $_status");
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
loadAnonymousUser() async {
|
||||
try {
|
||||
final user = await account.createAnonymousSession();
|
||||
_currentSession = user;
|
||||
_status = AuthStatus.AUTHENTICATED;
|
||||
|
||||
} catch (e) {
|
||||
_status = AuthStatus.UNAUTHENTICATED;
|
||||
} finally {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
loadUser() async {
|
||||
|
||||
Reference in New Issue
Block a user