简体   繁体   中英

Auth all users to Firebase

I have a firebase app for which I don't need or want user signup or login but I want to setup Auth to make sure database can only be accessed through my app. Is there any way to do so?

You can use Anonymous Authentication for that purpose. Users don't need to enter any details for sign up or login, Firebase will simply give them an uid to access your database and you can still keep your Firebase Security Rules set to auth!=null .

Go ahead, add Firebase Auth to your app and then on your Activity:

  1. Grab an instance of the FirebaseAuth Object: private FirebaseAuth mAuth; mAuth = FirebaseAuth.getInstance(); private FirebaseAuth mAuth; mAuth = FirebaseAuth.getInstance();
  2. Sign the user in, anonymously:

    mAuth.signInAnonymously() .addOnCompleteListener(this, new OnCompleteListener<AuthResult>(){ @Override public void onComplete(@NonNull Task<AuthResult> task){ if(task.isSuccessful()){ Log.d(TAG, "signInAnonymously:success"); } else { Log.w(TAG, "signInAnonymously:failure", task.getException()); Toast.makeText(AnonymousAuthActivity.this, "Failed", Toast.LENGTH_SHORT).show(); } } });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM