Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to logout facebook account for entring another account

I am using flutter facebook auth.

When I login for the first time came to enter email and password after that I logout and went to login again then it did not ask for email and password.

When I login for the first time came to enter email and password after that I logout and went to login again then it did not ask for email and password.

and its looks like it enter image description here

this is my facebook login functionality


import 'package:cwc/ApiManager/preference.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
final FirebaseAuth _auth = FirebaseAuth.instance;

// final GoogleSignIn googleSignIn = GoogleSignIn();

String? fbName;
String? fbEmail;
String? fbImageUrl;

Future<String?> signInWithFacebook() async {
  // Trigger the sign-in flow
  final LoginResult loginResult = await FacebookAuth.instance.login();
  // final GoogleSignInAccount? googleSignInAccount = await googleSignIn.signIn();
 var a= await loginResult.message;
  // Create a credential from the access token
  final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken!.token);
  print("facebookAuthCredential22 ${facebookAuthCredential.token}");
  print("facebookAuthCredential33 ${facebookAuthCredential.accessToken}");
  print("facebookAuthCredential44 ${facebookAuthCredential.rawNonce}");
  // Once signed in, return the UserCredential
  final UserCredential authResult =
  await _auth.signInWithCredential(facebookAuthCredential);
  final User? users = authResult.user;
  final UserInfo? user = users!.providerData[0];
  print("facebookAuthCredential11 $user");
  // return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);

  if (user != null) {
    // Checking if email and name is null
    // assert(user.email != null);
    assert(user.displayName != null);
    assert(user.photoURL != null);

    Preferences.saveData("socialName", user.displayName.toString());
    Preferences.saveData("socialEmail", user.email.toString());
    Preferences.saveData("socialImage", user.photoURL.toString());

    // Only taking the first part of the name, i.e., First Name
    // if (googleName!.contains(" ")) {
    //   googleName = googleName!.substring(0, googleName!.indexOf(" "));
    // }

    assert(!users.isAnonymous);
    assert(await users.getIdToken() != null);

    final User? currentUser = _auth.currentUser;
    assert(users.uid == currentUser!.uid);

    print('signInWithFacebook succeeded: $user');

    return '$user';
  }

  return null;
}

Future<void> signOutWithFacebook() async {
  await FacebookAuth.instance.logOut();
  print("User Signed Out");
}


like image 516
Deepak Avatar asked Oct 20 '25 02:10

Deepak


1 Answers

You'll also need to sign out of Facebook explicitly by calling:

FacebookAuth.instance.logOut()

Also see:

  • How to properly sign out of Facebook on Android with Firebase?
  • The documentation of flutter_facebook_auth on signing out
like image 55
Frank van Puffelen Avatar answered Oct 22 '25 03:10

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!