Forums

OverviewFelgo Plugins Support › Maintan firebase auth across pages

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19653

    Edward

    Hey!

    I have set up my custom auth for firebase in my login popup, which when I register users onto the database works perfectly. but when I attempt to read/write using the setUserValue&getUserValue controls my log shows I am not authenticated?

    I use a popup login screen on app launch for auth, how would I tie this in to my homepage to allow the auth to work across the entire app?

    I’m struggling to link the FirebaseDatabase on my homepage to connect to the customconfig in my loging popup page

    below is my homepage code. I would like the authentication to be maintained across the app as there will more than one page in the navigation which needs the authentication to function.

    Thanks!!!

    import Felgo 3.0
    import QtQuick 2.0
    import Felgo 3.0
    
    Page {
        id: mainPage
        title: "Home"
    
        signal logoutClicked()
        signal registrationRequired
    
        function logoutUser() {
            firebaseAuth.logoutUser()
        }
        ItemWithFirebaseLogin {
            id: loginPage
            opacity: 1
            z: 1 
            visible: opacity > 0
            enabled: visible
            Behavior on opacity { NumberAnimation { duration: 250 } }
        }
        FirebaseDatabase {
            id: firebaseDb
            config: customConfig
            onReadCompleted:  {
                if(success) {
                    console.debug("Read Value " + value + " for key" + key)
                } else {
                    console.debug("Error: " + value)
                }
                output.text = value
            }
            onWriteCompleted: {
                if(success) {
                    console.debug("Successfully wrote to DB")
                    output.text = "Successfully wrote to DB"
                } else {
                    console.debug("Write failed with error: " + message)
                    output.text = "Write failed with error: " + message
                }
            }
            onRealtimeUserValueChanged: {
              output.text = value
            }
        }
    }
    

     

    #19655

    Alex
    Felgo Team

    Hi Edward,

    why don’t you put your things like the FirebaseAuth or FirebaseDatabase in a scope that both pages can access, like making them a child of your App. Same for items like the config. Pages on a NavigationStack are lazy loaded and will be destroyed when popped, thus also your instances of the FIrebase items are destroyed.

    You could do something like this:

    App {
      FirebaseConfig {
        id: fbConfig
      }
      FirebaseAuth {
        id: fbAuth
      }
      FirebaseDatabase {
        id: fbDB
      }
      NavigationStack {
        Page {
          // ...
        }
      }
    }

    Then you can access all those items from anywhere in your App. If you want the logic in your page qml file, then just do this:

    Page {
      Connections {
        target: fbDB
        onReadCompleted:  {
          // ...
        }              
      }
    }

    Does that help you, do you get the idea?

    Cheers,
    Alex

    #19658

    Edward

    Thanks Alex,

    Makes so much sense haha!!

     

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support