Having Problems Designing Sign-In / Sign-Up Logic with Firebase + Android

后端 未结 1 868
暖寄归人
暖寄归人 2021-01-23 16:17

I\'m relatively new with Android/programming... I\'m trying to design an app that uses Firebase as the backend (although the problems I am having would exist for any app that tr

相关标签:
1条回答
  • 2021-01-23 16:52

    Well... since nobody has answered yet, I've still been working on this, and my best solution is:

    In the SignINActivity, when the user is successfully signed in, I will save a copy of their datasnapshot (profile) from the Firebase database in Shared Preferences. That way, when they return to the onResume() in MainActivity, it can use this snapshot to determine all the conditions I need without callbacks being involved. Subsequently, in signUPActivity, I will update the local snapshot when that is completed, also.

    I have replaced 'MainActivity' with a new launcher class, ActionDecider.

    ActionDecider.onResume() :

    @Override
    protected void onResume(){
        super.onResume();
    
        // TODO: do safetynet check here
    
    
        // (4) CONDITIONS :  HOW TO TELL :  WHAT TO DO
        // 
        // 1)not signed in : auth == null : load SignINActivity
        // 2)signed in, but not registered : snapshot == null : load SignUPActivity
        // 3)registered, but not approved : /userid/isAllowed == false : exit with dialog
        // 4)registered, and approved : /userid/isAllowed == true : continue as normal
    
    
    
        // if not signed in, go to signIn/Create account activity
    
            // user is sent to signIN which signs them in (or creates account), and saves a
            // datasnapshot of their db tree to shared prefs before returning here
    
    
        // (user is signed in)
    
        // CHECK: is user approved? (check the snapshot -- this is checked first because in 
        // most cases they will be approved, and this avoids an unnecessary extra check)
    
            // yes?  [exit] and load mainActivity. []
    
            // no?  CHECK:  is user signed up?
    
                    // no?  load signUP-Activity   (signUP activity UPDATES datasnapshot when complete)
    
                    // yes?  [exit] with dialog 
    
    }
    

    Best solution? I doubt it. But... feel free to let me know a better approach.

    0 讨论(0)
提交回复
热议问题