dash-auth icon indicating copy to clipboard operation
dash-auth copied to clipboard

Using dcc.Interval trigger invocation of auth_function on set interval

Open marcelonyc opened this issue 1 year ago • 0 comments

I have a dcc.Interval defined in one of my pages and BasicAuth for authentication with an auth_func. After I login, the auth_func is invoked on each interval. Is this behavior expected? If it is, what can I check in the auth_func to skip my credentials checking (avoid db/api call) when it is called in the interval?

auth_func

def authorization_function(username, password):
    print("Calling Auth: {}".format(datetime.now()))
    if (username == "hello") and (password == "world"):
        return True
    else:
        return False

private_user.py

from dash import html, dcc, register_page, callback, Output, Input
from datetime import datetime

register_page(__name__, path_template="/user/<user_id>/public")


def layout(user_id: str):
    return [
        html.H1(f"User {user_id} (authenticated only)"),
        html.Div("Members-only information"),
        html.Div(id="interval-holder"),
        dcc.Interval(id="interval-component", interval=3000),
    ]


@callback(
    Output("interval-holder", "children"),
    Input("interval-component", "n_intervals"),
)
def interval_update(n_intervals):
    return "Now is {}".format(datetime.now())

Output

Calling Auth: 2024-08-04 18:00:29.635157 Calling Auth: 2024-08-04 18:00:32.630609 Calling Auth: 2024-08-04 18:00:35.635867 Calling Auth: 2024-08-04 18:00:38.634269

marcelonyc avatar Aug 04 '24 18:08 marcelonyc