shinymanager logout by click on a button

Viewed 677

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?

1 Answers

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

Related