All checks were successful
ci/woodpecker/push/build Pipeline was successful
62 lines
1.7 KiB
Dart
62 lines
1.7 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:grpc/grpc_web.dart';
|
|
import 'package:softplayer_dart_proto/accounts/v1/accounts_v1.pbgrpc.dart';
|
|
import 'package:softplayer_web/core/grpc/grpc_client.dart';
|
|
|
|
final publicAccountsGrpcProvider = Provider<PublicAccountsGrpcRepository>((
|
|
ref,
|
|
) {
|
|
return PublicAccountsGrpcRepository(
|
|
ref.watch(publicAccountsServiceClientProvider),
|
|
);
|
|
});
|
|
|
|
class PublicAccountsGrpcRepository {
|
|
PublicAccountsGrpcRepository(this._client);
|
|
final PublicAccountsServiceClient _client;
|
|
|
|
Future<SignInResponse> signIn(SignInRequest req) async {
|
|
final call = _client.signIn(req);
|
|
try {
|
|
final response = await call;
|
|
return response;
|
|
} on GrpcError {
|
|
final headers = await call.headers;
|
|
final int? status = int.tryParse(headers['grpc-status'] ?? '');
|
|
switch (status) {
|
|
case StatusCode.notFound:
|
|
throw "Incorrect email or password. Please try again.";
|
|
case StatusCode.unauthenticated:
|
|
throw "Incorrect password";
|
|
default:
|
|
rethrow;
|
|
}
|
|
} catch (e) {
|
|
log("Unexpected error signing in: $e");
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<SignUpResponse> signUp(SignUpRequest req) async {
|
|
final call = _client.signUp(req);
|
|
try {
|
|
final response = await call;
|
|
return response;
|
|
} on GrpcError {
|
|
final headers = await call.headers;
|
|
final int? status = int.tryParse(headers['grpc-status'] ?? '');
|
|
switch (status) {
|
|
case StatusCode.alreadyExists:
|
|
throw "A user with this email already exists. Please use another one.";
|
|
default:
|
|
rethrow;
|
|
}
|
|
} catch (e) {
|
|
log("Unexpected error signing in: $e");
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|