paradigm shift
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
|
||||
class ApiConstants {
|
||||
|
||||
static const String APPWRITE_ENDPOINT = "https://cloud.imbenji.net/v1";
|
||||
static const String APPWRITE_PROJECT_ID = "65de530c1c0a7ffc0c3f";
|
||||
static const String APPWRITE_ENDPOINT = "https://cloud.appwrite.io/v1";
|
||||
static const String APPWRITE_PROJECT_ID = "6633d0e00023502890ed";
|
||||
|
||||
static const String INFO_Q_DATABASE_ID = "65de5cab16717444527b";
|
||||
static const String MANUAL_Q_COLLECTION_ID = "65de9f2f925562a2eda8";
|
||||
|
||||
@@ -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