intermediate

This commit is contained in:
Fabian Freund
2025-01-23 14:03:55 +01:00
parent bd45ed64ee
commit 78c17a70c5
122 changed files with 8730 additions and 1662 deletions
@@ -0,0 +1,52 @@
import 'package:lensai/features/user/domain/providers.dart';
import 'package:lensai/features/user/extensions/client_exception.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'auth.g.dart';
class AuthException implements Exception {
final String message;
AuthException(this.message);
@override
String toString() {
return message;
}
}
@Riverpod()
class AuthRepository extends _$AuthRepository {
late PocketBase _pb;
Future<RecordAuth> authWithPassword(String user, String password) async {
try {
return await _pb.collection('users').authWithPassword(user, password);
} on ClientException catch (e) {
throw AuthException(e.errorMessage);
}
}
Future<RecordModel> createUserWithPassword(
String email,
String password,
) async {
try {
return await _pb.collection('users').create(
body: {
"email": email,
"password": password,
"passwordConfirm": password,
},
);
} on ClientException catch (e) {
throw AuthException(e.errorMessage);
}
}
@override
void build() {
_pb = ref.watch(pocketBaseProvider);
}
}