Skip to content

Using dcc.Interval trigger invocation of auth_function on set interval #153

@marcelonyc

Description

@marcelonyc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions