From 624c4775954bfb957465d5ee3ac568428e42ca99 Mon Sep 17 00:00:00 2001 From: test-name Date: Thu, 18 Jul 2024 13:24:35 -0500 Subject: [PATCH] Merged logout button into this module --- pyproject.toml | 2 +- src/shinylive_auth.py | 8 +++++++- src_dev/app.py | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b39163e..c8b548e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "shinylive_auth" -version = "2024.6.14" +version = "2024.7.18" authors = [ {name="darrida", email="darrida.py@gmail.com"} ] diff --git a/src/shinylive_auth.py b/src/shinylive_auth.py index b1ff681..5966783 100644 --- a/src/shinylive_auth.py +++ b/src/shinylive_auth.py @@ -4,7 +4,7 @@ from pydantic import SecretStr from shiny import Inputs, Outputs, Session, module, reactive, render, ui -DEFAULT_MODULE_ID = "shiny_auth_module" +DEFAULT_AUTH_MODULE_ID = "shiny_auth_module" ########################################################################## @@ -108,6 +108,7 @@ def view(): ui.output_ui("read_token"), ), ), + ui.input_action_button("logout_btn", "Logout") ) @@ -131,6 +132,11 @@ def server( session_auth: AuthReactiveValues, app_auth: AuthProtocol ): + @reactive.effect + @reactive.event(input.logout_btn) + def _(): + session_auth.logout.set(True) + @reactive.effect def _(): token = session_auth.token.get() diff --git a/src_dev/app.py b/src_dev/app.py index 4fc952e..eb0b629 100644 --- a/src_dev/app.py +++ b/src_dev/app.py @@ -1,5 +1,5 @@ +# import shinyswatch import shinylive_auth as auth -import shinyswatch from shiny import App, Inputs, Outputs, Session, reactive, render, ui # from restapi_security.auth import RestAPIAuth as SampleAuth @@ -8,9 +8,9 @@ APP_GROUPS_REQUIRED = ["group1"] app_ui = ui.page_fluid( - auth.view(auth.DEFAULT_MODULE_ID), # <---- AUTH SETUP HERE - ui.output_ui("init_main_view"), # <---- AUTH SETUP HERE - shinyswatch.theme.minty(), + auth.view(auth.DEFAULT_AUTH_MODULE_ID), # <---- AUTH SETUP HERE (creates a logout button here) + ui.output_ui("init_main_view"), + # shinyswatch.theme.minty(), title="Test Auth Page", ) @@ -29,7 +29,7 @@ def server(input: Inputs, output: Outputs, session: Session): ################################################################################################# # AUTH SETUP HERE session_auth = auth.AuthReactiveValues() - auth.server(auth.DEFAULT_MODULE_ID, session_auth, app_auth=SampleAuth(groups_needed=APP_GROUPS_REQUIRED)) + auth.server(auth.DEFAULT_AUTH_MODULE_ID, session_auth, app_auth=SampleAuth(groups_needed=APP_GROUPS_REQUIRED)) @render.ui def init_main_view():