Tychobra / polished

Authentication and Administration for Shiny apps
https://polished.tech
Other
233 stars 36 forks source link

Issue with registering a new user when creating a fully custom sign page #227

Open EmmanuelUgo opened 3 months ago

EmmanuelUgo commented 3 months ago

Hi guys!

Great package, I came across a small issue while I was creating a custom shiny login page using the {polished} library.

I followed the guide provided here but it doesn’t seem to work well with registering a new user. When I click on the register button, nothing happens.

Here’s a reprex:

library(shiny)
library(polished)

my_custom_sign_in_module_ui <- tagList(
  shinyjs::useShinyjs(),
  # your custom sign in inputs

  div(
    id = "sign_in_page",
    email_input("sign_in_email"),
    password_input("sign_in_password"),
    actionButton("sign_in_submit",
                 "Sign In"),
    actionLink("go_to_register",
               "Not a member? Register!")
  ),

  # your custom registration inputs.  Your inputs
  shinyjs::hidden(
    div(
      id = "register_page",
      password_input("register_password"),
      password_input("register_password_verify"),
      actionButton("register_submit", "Register"),
      actionLink("go_to_sign_in", "Already a member? Sign in!")
    )
  ),

  # make sure to call this function somewhere in your sign in page UI.  It loads
  # the JavaScript used in the sign in and registration process.
  sign_in_js()  
)

my_custom_sign_in_module <- function(input, output, session) {
  # your custom sign in and registration server logic
  # We provide an example showing the sign in & registration pages separately

  # show the registration inputs & button
  observeEvent(input$go_to_register, {
    shinyjs::hideElement("sign_in_page")
    shinyjs::showElement("register_page")
  })

  # show the sign in inputs & button
  observeEvent(input$go_to_sign_in, {
    shinyjs::hideElement("register_page")
    shinyjs::showElement("sign_in_page")
  })

  jwt <- reactive({
    # optional: include additional authorization checks here
    input$check_jwt
  })

  sign_in_check_jwt(jwt)
}

ui <- secure_ui(ui = fluidPage(h1("I am a Shiny app!")),
                # you must pass "sign_in" sign in to your custom module `id` argument
                # as done below:
                sign_in_page_ui = my_custom_sign_in_module_ui)

server <- secure_server(
  server = function(input, output, session) {
  },
  custom_sign_in_server = my_custom_sign_in_module
)

shinyApp(
  ui,
  server,
  onStart = function() {
    polished_config(
      api_key = "<your polished.tech API key>",
      app_name = "<your app name from polished.tech>"
    )
  }
)

Thanks!