How the authentication modules work together
masterThe package provides two main modules consisting of a UI component and a Server component:
- Login Module:
loginUI()andloginServer()handle user credentials. - Logout Module:
logoutUI()andlogoutServer()handle session termination.
The credentials object
When loginServer() is called, it returns a reactive list containing two elements:
user_auth: A boolean (TRUEif authenticated,FALSEotherwise).info: A row of data from your provided data frame associated with the authenticated user (orNULLif not authenticated).
Workflow Pattern
- Use
req(credentials()$user_auth)inside your reactives, renders, and observers to ensure code only executes after a successful login. - The
logoutServer()module should be passed a reactive trigger based on theuser_authstatus to automatically show/hide the logout button.
# Minimal usage pattern
credentials <- shinyauthr::loginServer(
id = "login",
data = user_base,
user_col = user,
pwd_col = password,
log_out = reactive(logout_init())
)
logout_init <- shinyauthr::logoutServer(
id = "logout",
active = reactive(credentials()$user_auth)
)