Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mobile/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ analyzer:
invalid_return_type_for_catch_error: ignore
use_build_context_synchronously: ignore
use_null_aware_elements: ignore
exclude:
- build/**
- android/**
- ios/**
- web/**
- windows/**
- macos/**
- linux/**
include: package:flutter_lints/flutter.yaml

linter:
Expand Down
25 changes: 20 additions & 5 deletions mobile/lib/controllers/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:mobile/services/signal_service.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:app_links/app_links.dart';
import 'package:mobile/models/user.dart';
Expand Down Expand Up @@ -67,22 +68,21 @@ class AuthState extends ChangeNotifier {
final userData = data['data'] ?? data['user'] ?? data;

_currentUser = UserModel.fromJson(userData);

await _authService.saveUserProfile(jsonEncode(userData));
notifyListeners();

} catch (e) {
debugPrint("Network failed, attempting to load cached user profile: $e");

try {
final cachedData = await _authService.getCachedUserProfile();
if (cachedData != null) {
final decodedData = jsonDecode(cachedData);
_currentUser = UserModel.fromJson(decodedData);
notifyListeners();
} else {
_errorMessage = "No internet connection and no cached profile.";
notifyListeners();
_errorMessage = "No internet connection and no cached profile.";
notifyListeners();
}
} catch (cacheError) {
debugPrint("Cache read failed: $cacheError");
Expand All @@ -95,6 +95,9 @@ class AuthState extends ChangeNotifier {

if (_token != null) {
await loadUserProfile();
if (_currentUser != null) {
await SignalService().initializeAndUploadKeys(_currentUser!.id);
}
}

notifyListeners();
Expand Down Expand Up @@ -129,6 +132,10 @@ class AuthState extends ChangeNotifier {

await loadUserProfile();

if (_currentUser != null) {
await SignalService().initializeAndUploadKeys(_currentUser!.id);
}

_isLoading = false;
notifyListeners();
return true;
Expand Down Expand Up @@ -179,6 +186,10 @@ class AuthState extends ChangeNotifier {

await loadUserProfile();

if (_currentUser != null) {
await SignalService().initializeAndUploadKeys(_currentUser!.id);
}

_isLoading = false;
notifyListeners();
return true;
Expand Down Expand Up @@ -237,6 +248,10 @@ class AuthState extends ChangeNotifier {
await _authService.saveTokens(accessToken, refreshToken ?? accessToken);
await loadUserProfile();

if (_currentUser != null) {
await SignalService().initializeAndUploadKeys(_currentUser!.id);
}

_isLoading = false;
notifyListeners();
return true;
Expand Down
Loading
Loading