resolveAuthAccountId function
Resolves a provider account id from profile/user fields.
Implementation
String resolveAuthAccountId(
Map<String, dynamic> profile,
AuthUser user, {
required String Function() fallbackId,
bool emailVerified = false,
}) {
final candidates = <Object?>[
profile['sub'],
profile['id'],
profile['user_id'],
user.id,
if (emailVerified) user.email,
];
for (final value in candidates) {
final candidate = value?.toString().trim();
if (candidate != null && candidate.isNotEmpty) {
return candidate;
}
}
final fallback = fallbackId().trim();
if (fallback.isEmpty) {
throw StateError('OAuth provider returned no stable account identity');
}
return fallback;
}