Shiny authentication module to be used with signinUI. It uses shiny's new moduleServer method.
signinServer(
id,
users_db,
sodium_hashed = TRUE,
signout = shiny::reactiveVal(),
reload_on_signout = FALSE,
cookie_logins = FALSE,
sessionid_col,
cookie_getter,
cookie_setter
)The ID for the server module.
data.frame or tibble containing five columns: date_created,
username, password, name, email, and permissions.
See create_dummy_users.
have the passwords been hash encrypted using the sodium package? defaults to TRUE.
reactive supply the returned reactive from signoutServer here to trigger a user sign-out
logical to force a session reload on logout? defaults to FALSE.
enable automatic logins via browser cookies?
bare (unquoted) or quoted column name containing session ids
a function that returns a data.frame with at least two columns: user and session
a function with two parameters: user and session. The function must save these to a database.
The module will return a reactive six element list to your main application.
user_auth is a boolean indicating whether there has been
a successful login or not.
info will be the data frame provided
to the function, filtered to the row matching the successfully
logged in username. When user_auth is FALSE info is NULL.
cookie_already_checked TRUE OR FALSE.
users_db to be used in sign-up and password recovery features.
btn_signup to be passed to sign-up module.
btn_forgotpw to be passed to password recovery module.
library(shiny)
library(shinyAuthX)
# dataframe that holds usernames, passwords and other user data
users_base <- create_dummy_users()
ui <- fluidPage(
# add signout button UI
div(class = "pull-right", signoutUI(id = "signout")),
# add signin panel UI function without signup or password recovery panel
signinUI(id = "signin", .add_forgotpw = FALSE, .add_btn_signup = FALSE),
# setup output to show user info after signin
verbatimTextOutput("user_data")
)
server <- function(input, output, session) {
# Export reactive values for testing
exportTestValues(
auth_status = credentials()$user_auth,
auth_info = credentials()$info
)
# call the signout module with reactive trigger to hide/show
signout_init <- signoutServer(
id = "signout",
active = reactive(credentials()$user_auth)
)
# call signin module supplying data frame,
credentials <- signinServer(
id = "signin",
users_db = users_base,
sodium_hashed = TRUE,
reload_on_signout = FALSE,
signout = reactive(signout_init())
)
output$user_data <- renderPrint({
# use req to only render results when credentials()$user_auth is TRUE
req(credentials()$user_auth)
str(credentials())
})
}
if (interactive()) shinyApp(ui = ui, server = server)