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


i'm relatively new android/programming... i'm trying design app uses firebase backend (although problems having exist app tries make immediate decisions based on remote data).

i feel there smarter way i'm trying do.

the requirements (the way i'm thinking problem):

  • design app new users sign in , register (two separate things), app not allow them use app unless have been expicitly (manually) authorized human via firebase database console. existing/approved users bypass these stages.

so... solve this, have thought:

  1. when first open app, if not signed in, present them signin activity.

  2. if, upon successful sign-in, found have not yet registered, present registration activity.

  3. if upon successful registration, found not yet admin-approved, exit app alert dialog explaining must wait longer approval.

sounds simple... have mainactivity onresume() method this:

@override protected void onresume(){     super.onresume();      // if not signed in, go signin/create account activity      // (either signed in or return signin.java)      // if not signedup/registered, go signup/register activity      // (either signed or return register.java)      //  user admin-approved?  if not, exit.   } 

but problems arise when try implement these "checks."

how check whether user has registered? thought, well, can query firebase database... example:

  • to find out if user has registered, check branch (key) in json tree of firebase db matches signed in userid, know have registered (because registration activity have created record already)

  • to check whether admin-approved, check field such as:

    '\firebase\user_id\isallowed' = true.  

this field set false default , set true if admin manually sets value in database.

but these sort of remote checks take time execute... , results delivered via callback methods... how can "pause" onresume method waits result before continuing?? (we 'nest' callbacks within callbacks: firstcheck.onsuccess() { [secondcheck.onsuccess() { [thirdcheck.onsuccess() { // success! }] } ] } ... seems bad idea.

alright... why not use shared preferences instead, , have registration activity save "user_progress" variable such 1, meaning have completed registration? way user's progress stored locally , checked in onresume() logic.

but creates new problem... if user re-installs app? shared preferences wiped , believe not registered... , mistakenly present them registration activity again.

i have individual solutions these individual problems, results rat's nest of hard follow code...

has else been stuck kind of problem? going wrong in thinking? feel there fundamentally incorrect way i'm approaching it... procedural vs object oriented... , i'm wondering if can address that.

well... since nobody has answered yet, i've still been working on this, , best solution is:

in signinactivity, when user signed in, save copy of datasnapshot (profile) firebase database in shared preferences. way, when return onresume() in mainactivity, can use snapshot determine conditions need without callbacks being involved. subsequently, in signupactivity, update local snapshot when completed, also.

i have replaced 'mainactivity' new launcher class, actiondecider.

actiondecider.onresume() :

@override protected void onresume(){     super.onresume();      // todo: safetynet check here       // (4) conditions :  how tell :      //      // 1)not signed in : auth == null : load signinactivity     // 2)signed in, not registered : snapshot == null : load signupactivity     // 3)registered, not approved : /userid/isallowed == false : exit dialog     // 4)registered, , approved : /userid/isallowed == true : continue normal        // if not signed in, go signin/create account activity          // user sent signin signs them in (or creates account), , saves         // datasnapshot of db tree shared prefs before returning here       // (user signed in)      // check: user approved? (check snapshot -- checked first because in      // cases approved, , avoids unnecessary check)          // yes?  [exit] , load mainactivity. []          // no?  check:  user signed up?                  // no?  load signup-activity   (signup activity updates datasnapshot when complete)                  // yes?  [exit] dialog   } 

best solution? doubt it. but... feel free let me know better approach.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -