Should work for any dash app
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 14 11:46:49 2021
@author: DM_wo
"""
import dash
# import dashboard
from flask import Flask, session
from functools import wraps
def logout():
print("killing session")
def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
user = dict(session).get('user', None)
if (user is None):
return logout()
return f(*args, **kwargs)
return decorated_function
flask_app = Flask(__name__)
dash_base_path='/dash/'
BS = "https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/yeti/bootstrap.min.css"
dash_app = dash.Dash(server=flask_app, url_base_pathname=dash_base_path, external_stylesheets=[BS])
# dash_app.layout = dashboard.create_layout(dash_app)
# dashboard.create_callbacks(dash_app)
for view_func in flask_app.view_functions:
if view_func.startswith(dash_base_path):
flask_app.view_functions[view_func] = login_required(flask_app.view_functions[view_func])