Shiny UI module to be used with signupServer.
signupUI(id, ..., .header = NULL)
The ID for the UI module.
Additional arguments to be passed to the shiny::wellPanel function.
header for the sign-in panel, defaults to NULL
.
Shiny UI sign-up panel with text inputs for username
and password
,
name
, email
, as well as two action buttons, btn_signup
and btn_sigin
.
library(shiny)
library(mongolite)
library(shinyAuthX)
## default mongodb database server for testing: works only with `mtcars`
con <- mongo("mtcars", url = "mongodb+srv://readwrite:test@cluster0-84vdt.mongodb.net/test")
## remove any existing rows
con$drop()
## check
con$count()
#> [1] 0
# add users_base to con
create_dummy_users() |>
con$insert()
#> List of 5
#> $ nInserted : num 3
#> $ nMatched : num 0
#> $ nRemoved : num 0
#> $ nUpserted : num 0
#> $ writeErrors: list()
con$count()
#> [1] 3
ui <- fluidPage(
# add signout button UI
div(class = "pull-right", signoutUI(id = "signout")),
# add signin panel UI function with signup panel
signinUI(id = "signin", .add_forgotpw = FALSE, .add_btn_signup = TRUE),
# add signup panel
signupUI("signup"),
# 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 = con$find('{}'), ## add mongodb connection instead of tibble
sodium_hashed = TRUE,
reload_on_signout = FALSE,
signout = reactive(signout_init())
)
# call signup module supplying credentials() reactive
signupServer(
id = "signup", credentials = credentials, mongodb = con
)
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)