I’m making a project that involves using Flask and Pocketbase db for a website. Problem is everytime I switch to a page on a different blueprint, I have to reconnect and login to the Pocketbase server again using stored sessions. Here’s my example:
Main.py
from flask import * #MAKE SURE TO INSTALL FLASK BEFOREHAND
#from flask_ckeditor import CKEditor
from pocketbase import PocketBase #MAKE SURE TO INSTALL Pocketbase BEFOREHAND
from pocketbase.client import FileUpload
from user.user import user
from classroom.classroom import classroom
app = Flask(__name__)
app.register_blueprint(user, url_prefix="/user")
app.register_blueprint(classroom, url_prefix="/classroom")
client = PocketBase('https://####-#####.pockethost.io')
user.py
from flask import *
from pocketbase import PocketBase #MAKE SURE TO INSTALL Pocketbase BEFOREHAND
from pocketbase.client import FileUpload
user = Blueprint("user", __name__, static_folder="", template_folder="templates")
client = PocketBase('https://####-#####.pockethost.io')
@user.route("/")
def home():
if "login" in session:
if client.auth_store.base_model == None:
client.collection("users").auth_with_password(session["login"][0], session["login"][1])
classroom.py
from flask import *
from pocketbase import PocketBase #MAKE SURE TO INSTALL Pocketbase BEFOREHAND
from pocketbase.client import FileUpload
classroom = Blueprint("classroom", __name__, static_folder="", template_folder="templates")
client = PocketBase('https://####-#####.pockethost.io')
@classroom.route("/")
def home():
if "login" in session:
if client.auth_store.base_model == None:
client.collection("users").auth_with_password(session["login"][0], session["login"][1])
Is there a way so that I can just use one instance of Pocketbase for all blueprints?
I tried passing the Pocketbase instance through the sessions but it doesn’t work.
mana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.