im using firebase as my database in kivy project,I wanted to display main screen if a user is already logged in otherwise the login screen. How can i know if the person is logged in or out using python firebase api this is my code
from kivymd.app import MDApp
from kivymd.toast import toast
import firebase_admin
from firebase import Firebase
from firebase_admin import credentials,auth
from firebase_admin import db
cred = credentials.Certificate("C:/Users/RAJAT/Downloads/fir-50c26-firebase-adminsdk-rwle3-a9063a3375.json")
firebase_admin.initialize_app(cred,{'databaseURL':'https://fir-50c26.firebaseio.com/'})
config={
'apiKey':'AIzaSyCuvad-ZHHXVRp1Ly3AyOwgpPgG1zi-wJs',
'authDomain':'fir-50c26.firebaseapp.com',
'databaseURL':'https://fir-50c26.firebaseio.com/',
'storageBucket':'fir-50c26.appspot.com',
'serviceAccount':'C:/Users/RAJAT/Downloads/fir-50c26-firebase-adminsdk-rwle3-a9063a3375.json'
}
fb=Firebase(config)
au=fb.auth()
class DemoApp(MDApp):
def login(self):
uid = self.root.ids.username.text
pas = self.root.ids.password.text
try:
hi=au.sign_in_with_email_and_password(uid,pas)
self.root.current = 's3'
print(hi)
print('success')
except Exception as e:
e=str(e)
e=e.split(':')
e=e[6]
e=e.split(',')[0]
toast(e)
def signup(self):
usn=self.root.ids.User.text
email=self.root.ids.Email.text
phone=self.root.ids.Phone.text
phone='+91'+phone
pas=self.root.ids.Pass.text
try:
self.usr = auth.create_user(uid=usn, display_name=usn,phone_number=phone, email=email,password=pas)
except Exception as err:
err=str(err)
toast(err)
def signedinorno(self):
uid='raj'
user=auth.get_user(uid)
ar=au.get_account_info(user['idToken'])
DemoApp().run()
here i have used 2 api because python_firebase doesn't provide login option i guess, because i didnt get it in documentation.here is the link for the libraries that i have used, firebase_admin: https://pypi.org/project/firebase-admin/ and the api used for login is, firebase: https://pypi.org/project/firebase/