Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcelonyc opened this issue Aug 4, 2024 · 0 comments
Open

Comments

@marcelonyc
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant