检查用户是否登录了firebase python

时间:2020-08-16 17:00:20

标签: python firebase-authentication logout

我在基维项目中使用firebase作为我的数据库,如果用户已经登录,我想显示主屏幕,否则显示登录屏幕。我怎么知道该人是使用python firebase api登录还是注销 这是我的代码

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()

在这里我使用了2个api,因为我猜python_firebase没有提供登录选项,因为我没有在文档中得到它。这是我使用的库的链接, firebase_admin: https://pypi.org/project/firebase-admin/ 用于登录的api是 火力: https://pypi.org/project/firebase/

0 个答案:

没有答案
相关问题