paradigm shift

This commit is contained in:
ImBenji
2024-05-03 14:03:51 +01:00
parent 673891923d
commit 1f48f8f4b0
17 changed files with 2440 additions and 547 deletions

View File

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

View File

@@ -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 {