datastorm-open / shinymanager

Simple and secure authentification mechanism for single shiny applications.
https://datastorm-open.github.io/shinymanager/
381 stars 79 forks source link

I cannot get/store username and user role when using secure_app #120

Closed BrianCollinss closed 2 years ago

BrianCollinss commented 2 years ago

I have tried every way I could think of to get the username on the server side and change the UI based on the user role. But I cannot do that. Is there any easy way to get and store the username / password / role / etc when user inputs their username and password and log-in?

pvictor commented 2 years ago

Hello,

secure_server()return areactiveValueswith a slotuser` containing username. Here an example on how to use it:

library(shiny)
library(shinymanager)

ui <- secure_app(fluidPage(
  uiOutput(outputId = "hello", container = tags$h3),
  verbatimTextOutput("auth_output")
))

server <- function(input, output, session) {

  res_auth <- secure_server(
    check_credentials = check_credentials(data.frame(
      user = c("user1", "user2"),
      password = c("pwd", "pwd"),
      extra_info = c("info user1", "info user2")
    ))
  )

  output$hello <- renderUI({
    paste("Hello", res_auth$user, "!")
  })

  output$auth_output <- renderPrint({
    reactiveValuesToList(res_auth)
  })

}

shinyApp(ui, server)

Victor

BrianCollinss commented 2 years ago

Hi Victor. Is there any way I can pass this variable to UI as a character string, instead of wrapping it in a text?

pvictor commented 2 years ago

If you need to generate UI according to username it has to be server-side, in renderUI() for example.