Reputation: 1201
I would like to logout and auth screen to appear when the user clicks on a button.
credentials <- data.frame(
user = "x",
password = "x"
)
library(shiny)
library(shinymanager)
ui <- fluidPage(
tags$h2("My secure application"),
actionButton("action_logout", "Logout!")
)
ui <- secure_app(ui)
server <- function(input, output, session) {
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
observeEvent(input$action_logout, {
# logout
})
}
shinyApp(ui, server)
I found out that shinymanager's default logout button in the lower right corner has id = ".shinymanager_logout"
, so I tried to call that with session$sendCustomMessage(".shinymanager_logout", 1)
. That's probably a very naive way.
How can I logout the user with my custom logout button?
Upvotes: 4
Views: 1358
Reputation: 1
In the function secure_server
, the the button .shinymanager_logout
trigers this code:
observeEvent(session$input$.shinymanager_logout, {
token <- getToken(session = session)
logout_logs(token)
.tok$remove(token)
clearQueryString(session = session)
session$reload()
}, ignoreInit = TRUE)
So, I suppose you can logout the user using your custom logout button by replacing session$input$.shinymanager_logout
with you custom logout button id.
Upvotes: 0
Reputation: 13866
The easiest way to doing that is to reload the shiny session with session$reload()
, so in your example:
observeEvent(input$action_logout, {
session$reload()
})
But maybe we can implement something in the package, you can comment in this issue: https://github.com/datastorm-open/shinymanager/issues/7
Upvotes: 5