Skip to content

Commit

Permalink
Merged logout button into this module
Browse files Browse the repository at this point in the history
  • Loading branch information
dummyuser committed Jul 18, 2024
1 parent 8ea95d3 commit 624c477
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "shinylive_auth"
version = "2024.6.14"
version = "2024.7.18"
authors = [
{name="darrida", email="[email protected]"}
]
Expand Down
8 changes: 7 additions & 1 deletion src/shinylive_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


##########################################################################
Expand Down Expand Up @@ -108,6 +108,7 @@ def view():
ui.output_ui("read_token"),
),
),
ui.input_action_button("logout_btn", "Logout")
)


Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src_dev/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
)

Expand All @@ -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():
Expand Down

0 comments on commit 624c477

Please sign in to comment.