Skip to content

Commit

Permalink
feat(auth): remove anonymous login feature
Browse files Browse the repository at this point in the history
  • Loading branch information
salahamassi committed Jul 31, 2024
1 parent a119829 commit 103df37
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
13 changes: 2 additions & 11 deletions lib/app/app_run_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:universal_platform/universal_platform.dart';

class RunAppTasks extends RunTasks {

@override
Future<void> beforeRun(WidgetsBinding widgetsBinding) async {
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
if (!(Auth.check())) {
await Auth.loginAnonymous();
}
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
FlutterNativeSplash.remove();
}
Expand All @@ -45,17 +41,12 @@ class RunAppTasks extends RunTasks {
if (Auth.check()) {
sl<NotificationCenterProvider>().load();
sl<NotificationCenterProvider>().listen();

final firebaseMessaging =
sl<PushNotificationProvider>(instanceName: 'firebase_messaging');
final fcmToken = await firebaseMessaging.token;
if (fcmToken != null) {
Map<String, String?> body = {
'device_id': await DeviceInfo.deviceIdInfo(),
'device_type': DeviceInfo.getDeviceType(),
'token': fcmToken,
}..removeWhere((key, value) => value == null);
await sl<AuthApi>().updateToken(body);
// TODO: send fcm token to server
log('fcm token $fcmToken', name: 'RunAppTasks');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:bond_network/bond_network.dart';
import 'package:bond_notifications/bond_notifications.dart';
import 'package:dio/dio.dart';

class NotificationCenterRemoteDataSource extends NotificationCenterDataSource {
final ApiClient _client;
Expand All @@ -9,12 +10,11 @@ class NotificationCenterRemoteDataSource extends NotificationCenterDataSource {
@override
Future<ListResponse<ServerNotificationModel>> loadNotifications(
{String? nextUrl}) async {
// final Response<dynamic> response = await _client.get(
// nextUrl ?? NotificationsApis.notifications,
// headers: Api.headers(),
// );
// return mapListResponse(response);
return ListResponse<ServerNotificationModel>.fromJson(const {"data": []});
final Response<dynamic> response = await _client.get(
nextUrl ?? NotificationsApis.notifications,
headers: Api.headers(),
);
return mapListResponse(response);
}

@override
Expand Down
9 changes: 0 additions & 9 deletions lib/features/auth/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,4 @@ class Auth {
static User user() => Cache.get('user');

static String token() => Cache.get('token');

static Future<User?> loginAnonymous() async {
try {
final response = await sl<AuthApi>().anonymousLogin();
return response.data;
} catch (e) {
return null;
}
}
}
16 changes: 0 additions & 16 deletions lib/features/auth/data/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ class AuthApi {
.errorFactory(ServerError.fromJson)
.execute();

Future<UserMApiResult> anonymousLogin() => _bondFire
.post<UserMApiResult>('users/anonymous-login')
.factory(UserMApiResult.fromJson)
.errorFactory(ServerError.fromJson)
.cacheCustomKey('token', path: 'meta.token')
.cacheCustomKey('user', path: 'data')
.execute();

Future<UserMApiResult> login(Map<String, dynamic> body) => _bondFire
.post<UserMApiResult>('/users/login')
.body(body)
Expand All @@ -51,12 +43,4 @@ class AuthApi {
.factory(SuccessResponse.fromJson)
.errorFactory(ServerError.fromJson)
.execute();

Future<SuccessResponse> updateToken(Map<String, dynamic> body) => _bondFire
.post<SuccessResponse>('notifications/update-token')
.header(Api.headers())
.body(body)
.factory(SuccessResponse.fromJson)
.errorFactory(ServerError.fromJson)
.execute();
}

0 comments on commit 103df37

Please sign in to comment.