注册问题修复

This commit is contained in:
roxy 2026-04-30 20:11:12 +08:00
parent 6a95763436
commit fa516a94e1
6 changed files with 100 additions and 23 deletions

View File

@ -15,8 +15,10 @@ import 'package:yumi/app/constants/sc_screen.dart';
import 'package:yumi/app/routes/sc_routes.dart'; import 'package:yumi/app/routes/sc_routes.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart'; import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/shared/tools/sc_date_utils.dart'; import 'package:yumi/shared/tools/sc_date_utils.dart';
import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart'; import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart'; import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
import 'package:yumi/shared/data_sources/models/enum/sc_auth_type.dart';
import 'package:yumi/shared/business_logic/models/res/login_res.dart'; import 'package:yumi/shared/business_logic/models/res/login_res.dart';
import 'package:yumi/services/general/sc_app_general_manager.dart'; import 'package:yumi/services/general/sc_app_general_manager.dart';
import 'package:yumi/services/auth/user_profile_manager.dart'; import 'package:yumi/services/auth/user_profile_manager.dart';
@ -612,16 +614,42 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
userProvider?.updateBornDay(birthdayDate.day); userProvider?.updateBornDay(birthdayDate.day);
num age = DateTime.now().year - birthdayDate.year; num age = DateTime.now().year - birthdayDate.year;
userProvider?.updateAge(age.abs()); userProvider?.updateAge(age.abs());
String authType = final authProvider = Provider.of<SocialChatAuthenticationManager>(
Provider.of<SocialChatAuthenticationManager>( context,
context, listen: false,
listen: false, );
).authType; String authType = authProvider.authType.trim();
String idToken = String idToken = authProvider.uid.trim();
Provider.of<SocialChatAuthenticationManager>( if (authType.isEmpty || idToken.isEmpty) {
context, final cachedAuthType = DataPersistence.getPendingChannelAuthType().trim();
listen: false, final cachedOpenId = DataPersistence.getPendingChannelAuthOpenId().trim();
).uid; if (authType.isEmpty) {
authType = cachedAuthType;
}
if (idToken.isEmpty) {
idToken = cachedOpenId;
}
}
if (authType.isEmpty || idToken.isEmpty) {
try {
final googleUser =
SCGoogleAuthService.currentUser ??
await SCGoogleAuthService.signInSilently();
final googleUid = googleUser?.uid.trim() ?? "";
if (googleUid.isNotEmpty) {
authType = SCAuthType.GOOGLE.name;
idToken = googleUid;
}
} catch (e) {
debugPrint('resolve register auth failed: $e');
}
}
if (authType.isEmpty || idToken.isEmpty) {
SCLoadingManager.hide();
SCTts.show("Please sign in again.");
return;
}
await DataPersistence.setPendingChannelAuth(authType, idToken);
final invitationCode = invitationCodeController.text.trim(); final invitationCode = invitationCodeController.text.trim();
SocialChatLoginRes user = await SCAccountRepository().regist( SocialChatLoginRes user = await SCAccountRepository().regist(
authType, authType,
@ -683,6 +711,7 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
return; return;
} }
AccountStorage().setCurrentUser(user); AccountStorage().setCurrentUser(user);
await DataPersistence.clearPendingChannelAuth();
userProvider?.syncCurrentUserProfile(user.userProfile); userProvider?.syncCurrentUserProfile(user.userProfile);
await DataPersistence.clearPendingRegisterRewardDialog(); await DataPersistence.clearPendingRegisterRewardDialog();
await DataPersistence.setAwaitRegisterRewardSocket(true); await DataPersistence.setAwaitRegisterRewardSocket(true);

View File

@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@ -11,7 +10,6 @@ import 'package:provider/provider.dart';
import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart'; import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart'; import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/ui_kit/components/custom_cached_image.dart'; import 'package:yumi/ui_kit/components/custom_cached_image.dart';
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
import 'package:yumi/shared/business_logic/models/res/country_res.dart'; import 'package:yumi/shared/business_logic/models/res/country_res.dart';
import 'package:yumi/services/general/sc_app_general_manager.dart'; import 'package:yumi/services/general/sc_app_general_manager.dart';
import 'package:yumi/services/auth/user_profile_manager.dart'; import 'package:yumi/services/auth/user_profile_manager.dart';
@ -21,19 +19,17 @@ import '../../app/config/business_logic_strategy.dart';
/// ///
class CountryPage extends StatefulWidget { class CountryPage extends StatefulWidget {
bool isDialog = false; final bool isDialog;
CountryPage({this.isDialog = false}); const CountryPage({super.key, this.isDialog = false});
@override @override
_CountryPageState createState() => _CountryPageState(isDialog); State<CountryPage> createState() => _CountryPageState();
} }
class _CountryPageState extends State<CountryPage> { class _CountryPageState extends State<CountryPage> {
bool isDialog = false;
Country? selectCountryInfo; Country? selectCountryInfo;
bool _didConfirmSelection = false;
_CountryPageState(this.isDialog);
@override @override
void initState() { void initState() {
@ -43,10 +39,12 @@ class _CountryPageState extends State<CountryPage> {
@override @override
void dispose() { void dispose() {
Provider.of<SCAppGeneralManager>( if (!_didConfirmSelection) {
context, Provider.of<SCAppGeneralManager>(
listen: false, context,
).clearCountrySelection(); listen: false,
).clearCountrySelection();
}
super.dispose(); super.dispose();
} }
@ -98,6 +96,7 @@ class _CountryPageState extends State<CountryPage> {
provider.updateCurrentCountry( provider.updateCurrentCountry(
selectCountryInfo, selectCountryInfo,
); );
_didConfirmSelection = true;
SCNavigatorUtils.goBack(context); SCNavigatorUtils.goBack(context);
} }
}, },
@ -159,6 +158,7 @@ class _CountryPageState extends State<CountryPage> {
provider.updateCurrentCountry( provider.updateCurrentCountry(
selectCountryInfo, selectCountryInfo,
); );
_didConfirmSelection = true;
SmartDialog.dismiss(tag: "showCountryPage"); SmartDialog.dismiss(tag: "showCountryPage");
} }
}, },

View File

@ -9,6 +9,7 @@ import 'package:yumi/app_localizations.dart';
import 'package:yumi/shared/tools/sc_version_utils.dart'; import 'package:yumi/shared/tools/sc_version_utils.dart';
import 'package:yumi/shared/tools/sc_google_auth_utils.dart'; import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
import 'package:yumi/shared/data_sources/models/enum/sc_auth_type.dart'; import 'package:yumi/shared/data_sources/models/enum/sc_auth_type.dart';
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart'; import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart'; import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
import 'package:yumi/shared/business_logic/models/res/login_res.dart'; import 'package:yumi/shared/business_logic/models/res/login_res.dart';
@ -485,11 +486,13 @@ class _SplashPageState extends State<SplashPage> {
if (uid.isEmpty) { if (uid.isEmpty) {
return null; return null;
} }
await DataPersistence.setPendingChannelAuth(SCAuthType.GOOGLE.name, uid);
final user = await SCAccountRepository().loginForChannel( final user = await SCAccountRepository().loginForChannel(
SCAuthType.GOOGLE.name, SCAuthType.GOOGLE.name,
uid, uid,
); );
AccountStorage().setCurrentUser(user); AccountStorage().setCurrentUser(user);
await DataPersistence.clearPendingChannelAuth();
return user; return user;
} catch (e) { } catch (e) {
debugPrint('restore login session failed: $e'); debugPrint('restore login session failed: $e');

View File

@ -1,13 +1,13 @@
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart'; import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:yumi/app/routes/sc_routes.dart'; import 'package:yumi/app/routes/sc_routes.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart'; import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/shared/tools/sc_google_auth_utils.dart'; import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
import 'package:yumi/shared/tools/sc_loading_manager.dart'; import 'package:yumi/shared/tools/sc_loading_manager.dart';
import 'package:yumi/shared/tools/sc_version_utils.dart'; import 'package:yumi/shared/tools/sc_version_utils.dart';
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart'; import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart'; import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
import 'package:yumi/shared/business_logic/models/res/login_res.dart'; import 'package:yumi/shared/business_logic/models/res/login_res.dart';
@ -39,6 +39,11 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
Future<void> _verifyExistingSession() async { Future<void> _verifyExistingSession() async {
final user = await SCGoogleAuthService.signInSilently(); final user = await SCGoogleAuthService.signInSilently();
_user = user; _user = user;
if (user != null) {
authType = SCAuthType.GOOGLE.name;
uid = user.uid;
await DataPersistence.setPendingChannelAuth(authType, uid);
}
notifyListeners(); notifyListeners();
} }
@ -53,6 +58,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
uid = _user!.uid; uid = _user!.uid;
SCLoadingManager.show(); SCLoadingManager.show();
if (uid.isNotEmpty) { if (uid.isNotEmpty) {
await DataPersistence.setPendingChannelAuth(authType, uid);
final res = await Future.wait([ final res = await Future.wait([
SCAccountRepository().loginForChannel(authType, uid), SCAccountRepository().loginForChannel(authType, uid),
SCVersionUtils.checkReview(), SCVersionUtils.checkReview(),
@ -74,6 +80,10 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
return; return;
} }
AccountStorage().setCurrentUser(user); AccountStorage().setCurrentUser(user);
await DataPersistence.clearPendingChannelAuth();
if (!context.mounted) {
return;
}
SCLoadingManager.hide(); SCLoadingManager.hide();
notifyListeners(); notifyListeners();
SCNavigatorUtils.push(context, SCRoutes.home, replace: true); SCNavigatorUtils.push(context, SCRoutes.home, replace: true);
@ -93,6 +103,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
uid = appleCredential.userIdentifier ?? ""; uid = appleCredential.userIdentifier ?? "";
SCLoadingManager.show(); SCLoadingManager.show();
if (uid.isNotEmpty) { if (uid.isNotEmpty) {
await DataPersistence.setPendingChannelAuth(authType, uid);
final res = await Future.wait([ final res = await Future.wait([
SCAccountRepository().loginForChannel(authType, uid), SCAccountRepository().loginForChannel(authType, uid),
SCVersionUtils.checkReview(), SCVersionUtils.checkReview(),
@ -114,6 +125,10 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
return; return;
} }
AccountStorage().setCurrentUser(user); AccountStorage().setCurrentUser(user);
await DataPersistence.clearPendingChannelAuth();
if (!context.mounted) {
return;
}
SCLoadingManager.hide(); SCLoadingManager.hide();
notifyListeners(); notifyListeners();
SCNavigatorUtils.push(context, SCRoutes.home, replace: true); SCNavigatorUtils.push(context, SCRoutes.home, replace: true);
@ -127,6 +142,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
Future<void> logoutUser() async { Future<void> logoutUser() async {
await SCGoogleAuthService.signOut(); await SCGoogleAuthService.signOut();
await DataPersistence.clearPendingChannelAuth();
_user = null; _user = null;
notifyListeners(); notifyListeners();
} }

View File

@ -10,6 +10,9 @@ class DataPersistence {
"await_register_reward_socket"; "await_register_reward_socket";
static const String _pendingRegisterRewardDialogKey = static const String _pendingRegisterRewardDialogKey =
"pending_register_reward_dialog"; "pending_register_reward_dialog";
static const String _pendingChannelAuthTypeKey = "pending_channel_auth_type";
static const String _pendingChannelAuthOpenIdKey =
"pending_channel_auth_open_id";
static SharedPreferences? _prefs; static SharedPreferences? _prefs;
static bool _isInitialized = false; static bool _isInitialized = false;
static Completer<void>? _initializationCompleter; static Completer<void>? _initializationCompleter;
@ -215,6 +218,31 @@ class DataPersistence {
return await remove(_awaitRegisterRewardSocketKey); return await remove(_awaitRegisterRewardSocketKey);
} }
static Future<void> setPendingChannelAuth(
String authType,
String openId,
) async {
await Future.wait([
setString(_pendingChannelAuthTypeKey, authType),
setString(_pendingChannelAuthOpenIdKey, openId),
]);
}
static String getPendingChannelAuthType() {
return getString(_pendingChannelAuthTypeKey);
}
static String getPendingChannelAuthOpenId() {
return getString(_pendingChannelAuthOpenIdKey);
}
static Future<void> clearPendingChannelAuth() async {
await Future.wait([
remove(_pendingChannelAuthTypeKey),
remove(_pendingChannelAuthOpenIdKey),
]);
}
/// ///
static String getUserRoomMusic() { static String getUserRoomMusic() {
final currentUser = AccountStorage().getCurrentUser()?.userProfile?.account; final currentUser = AccountStorage().getCurrentUser()?.userProfile?.account;

View File

@ -161,6 +161,7 @@ class AccountStorage {
_currentUser = null; _currentUser = null;
DataPersistence.setToken(""); DataPersistence.setToken("");
DataPersistence.setCurrentUser(""); DataPersistence.setCurrentUser("");
unawaited(DataPersistence.clearPendingChannelAuth());
unawaited(DurableAuthStorage.clearSession()); unawaited(DurableAuthStorage.clearSession());
} }