0

In my app, user is registered and authenticated using firebase. All activities in the app is accessible for authenticated users only. But inside app, there is one activity(ActivityB) which is user based data. this activity is again restricted with email&password login(so that a person who didn't installed the app can check this activity from other user).

Suppose user1 is registered on the app and authenticted by firebase. He will be authenticated throughout entire app. when user2 access ActivityB, and he can access his own data. But when when he signout, I need user1 to be automatically authenticated back as before.

How can i do this?

Even if User1/user2 signout from ActivityB, user is signout from entire firebase Authentication.

what i have give is just signout command. But it doesnt work

public void signout (View v)
    {
        auth.signOut();
        Intent i = new Intent(this,ActivityB.class);
        startActivity(i);
    }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Irfan
  • 35
  • 1
  • 7
  • Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should **only** be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See [when is it appropriate to remove an IDE tag](https://meta.stackoverflow.com/a/315196/6296561), [How do I avoid misusing tags?](https://meta.stackoverflow.com/q/354427/6296561), and [the tagging guide](/help/tagging). Use [android] or other relevant tags instead. – Zoe Jul 06 '20 at 13:15

1 Answers1

1

It sounds like you want two users to be signed in to Firebase Authentication inside your app. This is not a common scenario, so you'll have to do a bit of legwork to get it working.

The most important thing to realize is that only a single user can be signed in to each FirebaseAuth instance. So to allow two users to be signed in, you'll need to create two FirebaseAuth instances.

You'll normally create a default FirebaseAuth instance with FirebaseAuth.getInstance(). To get a secondary FirebaseAuth instance, follow the instructions on setting up multiple projects in a single application. You can use the same settings that you're using for the default FirebaseApp instance, but you'll have to specify them in your code here.

So it'll look something like:

FirebaseOptions options = new FirebaseOptions.Builder()
        .setProjectId("my-firebase-project")
        .setApplicationId("1:27992087142:android:ce3b6448250083d1")
        .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")
        // setDatabaseURL(...)
        // setStorageBucket(...)
        .build();
FirebaseApp secondary = FirebaseApp.initializeApp(this /* Context */, options, "secondary");

And then sign in to that FirebaseApp instance with:

FirebaseAuth.getInstance(secondary).signIn...

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807