Hi Everybody,
I am trying to get some data when i login with facebook. But for some reason i get that the url is null which is strange because when i debug i see the picture url clearly.
I did use custom jwt for google auth and with that, it works fine.
the code:
class RealmService with ChangeNotifier {
final String appId = "xxx";
late final appConfig = AppConfiguration(appId);
late final _app = App(appConfig);
late final user = _app.currentUser;
late realmModel.User? currentUser;
static final RealmService _singleton = RealmService._internal();
factory RealmService() {
return _singleton;
}
RealmService._internal();
Future<userModel.User> loginWithFacebook() async {
final LoginResult result = await FacebookAuth.instance.login();
final AccessToken accessToken = result.accessToken!;
final credentials = Credentials.facebook(accessToken.token);
final user = await _app.logIn(credentials);
currentUser = user;
final AuthLink authLink = AuthLink(
getToken: () async {
return 'Bearer ${accessToken.token}';
},
);
final Link link = authLink.concat(ApiConstants.httpLink);
final GraphQLClient client = GraphQLClient(
link: link,
cache: GraphQLCache(),
);
final MutationOptions options = MutationOptions(
document: gql('''
mutation Login(\$displayName: String!, \$email: String!, \$photoUrl: String!, \$userId: String!, \$isActive: Boolean!) {
login(displayName: \$displayName, email: \$email, photoUrl: \$photoUrl, userId: \$userId, isActive: \$isActive) {
userId
email
displayName
photoUrl
isActive
}
}
'''),
variables: <String, dynamic>{
'displayName': user.profile.name ?? 'Unknown',
'email': user.profile.email!,
'photoUrl':
"https://lh3.googleusercontent.com/a/AAcHTtdqfVKF9LdpoeF6gFfvB0IAxS0o1phC9a0-ncSw=s96-c",
// 'photoUrl': user.profile.pictureUrl!,
'userId': user.id,
'isActive': true
},
);
final QueryResult result2 = await client.mutate(options);
if (result2.hasException) {
throw Exception('Error logging in: ${result2.exception}');
}
await currentUser!.refreshCustomData(); // Refresh the custom data
logger.d(currentUser!.customData);
final data = result2.data!['login'];
user2 = userModel.User.fromJson(data);
final storage = FlutterSecureStorage();
// await storage.write(key: 'jwtToken', value: ggAuth.idToken!);
_token = _app.currentUser!.accessToken;
final customUserData = user.customData; // Access the custom data
await currentUser!.refreshCustomData(); // Refresh the custom data
logger.d(customUserData);
notifyListeners();
return user2;
}
anyone any idea why this is the case?