From d68c496d0c852b5c563ea4e0084fdf834ce8cdc7 Mon Sep 17 00:00:00 2001 From: Robert Norberg <132476312+robert-norberg@users.noreply.github.com> Date: Tue, 20 May 2025 11:58:57 -0400 Subject: [PATCH 1/4] Create current_user_hook.py Adds callback_context.custom_data["user"] to all calback contexts --- dash_auth/current_user_hook.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dash_auth/current_user_hook.py diff --git a/dash_auth/current_user_hook.py b/dash_auth/current_user_hook.py new file mode 100644 index 0000000..01450b3 --- /dev/null +++ b/dash_auth/current_user_hook.py @@ -0,0 +1,11 @@ +import flask + +from dash import hooks + +@hooks.custom_data("user") +def custom_data_func(_ctx): + try: + cu = flask.session["user"] + except AttributeError as e: + cu = {} + return cu From 38aa212e59cd5dbf77a0b264419d3cb14560b6a0 Mon Sep 17 00:00:00 2001 From: Robert Norberg <132476312+robert-norberg@users.noreply.github.com> Date: Tue, 20 May 2025 12:02:00 -0400 Subject: [PATCH 2/4] Add current user to callback_context --- dash_auth/current_user_hook/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dash_auth/current_user_hook/__init__.py diff --git a/dash_auth/current_user_hook/__init__.py b/dash_auth/current_user_hook/__init__.py new file mode 100644 index 0000000..01450b3 --- /dev/null +++ b/dash_auth/current_user_hook/__init__.py @@ -0,0 +1,11 @@ +import flask + +from dash import hooks + +@hooks.custom_data("user") +def custom_data_func(_ctx): + try: + cu = flask.session["user"] + except AttributeError as e: + cu = {} + return cu From e0693bc07bdff8ab60dce62ae8ef49e594a792db Mon Sep 17 00:00:00 2001 From: Robert Norberg <132476312+robert-norberg@users.noreply.github.com> Date: Tue, 20 May 2025 12:02:20 -0400 Subject: [PATCH 3/4] Delete dash_auth/current_user_hook.py --- dash_auth/current_user_hook.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 dash_auth/current_user_hook.py diff --git a/dash_auth/current_user_hook.py b/dash_auth/current_user_hook.py deleted file mode 100644 index 01450b3..0000000 --- a/dash_auth/current_user_hook.py +++ /dev/null @@ -1,11 +0,0 @@ -import flask - -from dash import hooks - -@hooks.custom_data("user") -def custom_data_func(_ctx): - try: - cu = flask.session["user"] - except AttributeError as e: - cu = {} - return cu From 523f918729fe3c917561387d6dd35a7b2a7ecf3d Mon Sep 17 00:00:00 2001 From: Robert Norberg <132476312+robert-norberg@users.noreply.github.com> Date: Tue, 20 May 2025 12:03:57 -0400 Subject: [PATCH 4/4] Add current_user_hook on import --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 8ba759b..9086418 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ }, python_requires=">=3.8", include_package_data=True, + entrypoints={"dash_hooks": ["current_user_hook = current_user_hook"]}, url='https://plotly.com/dash', classifiers=[ 'Development Status :: 5 - Production/Stable',