Skip to content

Commit

Permalink
Merge pull request #14 from fballan93/upgrade-to-appwrite-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Oct 30, 2022
2 parents f251e4e + f623de0 commit 7ac1dac
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 79 deletions.
32 changes: 16 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: appwrite
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0"
version: "8.1.0"
appwrite_auth_kit:
dependency: "direct main"
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
Expand All @@ -49,7 +49,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -119,7 +119,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -150,21 +150,21 @@ packages:
name: flutter_web_auth_2
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.2"
flutter_web_auth_2_platform_interface:
dependency: transitive
description:
name: flutter_web_auth_2_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.2"
flutter_web_auth_2_windows:
dependency: transitive
description:
name: flutter_web_auth_2_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.2"
flutter_web_plugins:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -197,21 +197,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
package_info_plus:
dependency: transitive
description:
Expand Down Expand Up @@ -260,7 +260,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -342,7 +342,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -363,21 +363,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
typed_data:
dependency: transitive
description:
Expand Down
49 changes: 27 additions & 22 deletions lib/src/accounts_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appwrite/appwrite.dart';
import 'package:appwrite/models.dart';
import 'package:appwrite/models.dart' as model;
import 'package:flutter/widgets.dart';

extension AppwriteAuthKitExt on BuildContext {
Expand Down Expand Up @@ -41,7 +41,8 @@ class AuthNotifier extends ChangeNotifier {
late final Account _account;
final Client _client;
AuthStatus _status = AuthStatus.uninitialized;
User? _user;

model.Account? _user;
String? _error;
late bool _loading;

Expand All @@ -56,7 +57,7 @@ class AuthNotifier extends ChangeNotifier {
Client get client => _client;
String? get error => _error;
bool get isLoading => _loading;
User? get user => _user;
model.Account? get user => _user;
AuthStatus get status => _status;

Future _getUser({bool notify = true}) async {
Expand Down Expand Up @@ -130,7 +131,7 @@ class AuthNotifier extends ChangeNotifier {
_status = AuthStatus.authenticating;
notifyListeners();
try {
await _account.createPhoneSession(userId: userId, number: number);
await _account.createPhoneSession(userId: userId, phone: number);
return true;
} on AppwriteException catch (e) {
_error = e.message;
Expand Down Expand Up @@ -210,7 +211,7 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<Jwt?> createJWT() async {
Future<model.Jwt?> createJWT() async {
try {
return await _account.createJWT();
} on AppwriteException catch (e) {
Expand All @@ -222,7 +223,7 @@ class AuthNotifier extends ChangeNotifier {

/// Create account
///
Future<User?> create({
Future<model.Account?> create({
required String email,
required String password,
String userId = 'unique()',
Expand Down Expand Up @@ -265,7 +266,8 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<User?> updatePrefs({required Map<String, dynamic> prefs}) async {
Future<model.Account?> updatePrefs(
{required Map<String, dynamic> prefs}) async {
try {
_user = await _account.updatePrefs(prefs: prefs);
notifyListeners();
Expand All @@ -277,9 +279,12 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<LogList?> getLogs({int? limit, int? offset}) async {
Future<model.LogList?> getLogs({int? limit, int? offset}) async {
try {
return await _account.getLogs(limit: limit, offset: offset);
return await _account.listLogs(queries: [
if (limit != null) Query.limit(limit),
if (offset != null) Query.offset(offset),
]);
} on AppwriteException catch (e) {
_error = e.message;
notifyListeners();
Expand All @@ -291,7 +296,7 @@ class AuthNotifier extends ChangeNotifier {
required String provider,
String? success,
String? failure,
List? scopes,
List<String>? scopes,
}) async {
try {
await _account.createOAuth2Session(
Expand All @@ -309,7 +314,7 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<Session?> getSession({required String sessionId}) async {
Future<model.Session?> getSession({required String sessionId}) async {
try {
return await _account.getSession(sessionId: sessionId);
} on AppwriteException catch (e) {
Expand All @@ -319,17 +324,17 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<SessionList?> getSessions() async {
Future<model.SessionList?> getSessions() async {
try {
return await _account.getSessions();
return await _account.listSessions();
} on AppwriteException catch (e) {
_error = e.message;
notifyListeners();
return null;
}
}

Future<User?> updateName({required String name}) async {
Future<model.Account?> updateName({required String name}) async {
try {
_user = await _account.updateName(name: name);
notifyListeners();
Expand All @@ -341,12 +346,12 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<User?> updatePhone({
Future<model.Account?> updatePhone({
required String number,
required String password,
}) async {
try {
_user = await _account.updatePhone(number: number, password: password);
_user = await _account.updatePhone(phone: number, password: password);
notifyListeners();
return _user;
} on AppwriteException catch (e) {
Expand All @@ -356,7 +361,7 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<User?> updateEmail({
Future<model.Account?> updateEmail({
required String email,
required String password,
}) async {
Expand All @@ -371,7 +376,7 @@ class AuthNotifier extends ChangeNotifier {
}
}

Future<User?> updatePassword({
Future<model.Account?> updatePassword({
required String password,
String? oldPassword,
}) async {
Expand All @@ -388,7 +393,7 @@ class AuthNotifier extends ChangeNotifier {
}

//createRecovery
Future<Token?> createRecovery({
Future<model.Token?> createRecovery({
required String email,
required String url,
}) async {
Expand All @@ -402,7 +407,7 @@ class AuthNotifier extends ChangeNotifier {
}

//updateRecovery
Future<Token?> updateRecovery({
Future<model.Token?> updateRecovery({
required String userId,
required String password,
required String passwordAgain,
Expand All @@ -422,7 +427,7 @@ class AuthNotifier extends ChangeNotifier {
}

//createVerification
Future<Token?> createVerification({required String url}) async {
Future<model.Token?> createVerification({required String url}) async {
try {
return await _account.createVerification(url: url);
} on AppwriteException catch (e) {
Expand All @@ -433,7 +438,7 @@ class AuthNotifier extends ChangeNotifier {
}

//updateVerification
Future<Token?> updateVerification({
Future<model.Token?> updateVerification({
required String userId,
required String secret,
}) async {
Expand Down
Loading

0 comments on commit 7ac1dac

Please sign in to comment.