@webhandle/login
v1.0.0
Published
Simple tools to handle user login and logout.
Readme
@webhandle/login
Simple tools to handle user login and logout.
Install
npm install @webhandle/loginUsage
import setupLogin from "@webhandle/login/initialize-webhandle-component.mjs"
let loginManager = await setupLogin(webhandle)Configuration
Configuration works like:
{
"@webhandle/login": {
"loginPostUrl": "/login"
, "logoutUrl": "/logout"
, "afterLogoutUrl": "/login"
, "accessErrorUrl": "/login"
, "postLoginDest": {
"administrators": "/admin/menu-administrators"
}
, "accessAllowed": {
"/admin/menu-administrators": ["administrators"]
}
, "forceLowerCaseUsernames": true
, "setupUserErrorHandlers": true
}
}loginPostUrl : This is where login forms should submit the username and password
logoutUrl : This URL will cause the user to be logged out
afterLogoutUrl : This is where the user is redirected after logout
accessErrorUrl : Where to direct the user if the user is not signed in or lacks permissions.
forceLowerCaseUsernames : Will make all usernames lower case before trying to login. This is necessary for any site which allows non-admin user to sign in, especially if they're using email addresses as usernames.
setupUserErrorHandlers
: If true it will watch for the Errors from @webhandle/users-data/errors and create an error message
and redirect. This will be reasonable behavior by default, but may not be complex enough in a full application.
postLoginDest : Determines where users will be directed after successful login
accessAllowed : If this is defined, it will set up authorization requirements for these endpoints.
postLoginHandler, userMenuAuthorization, and errorHandler are the functions which will actually be used
to perform the lifecycle tasks. They can't be set in the config file, but can be set after the component is loaded
like
loginManager.config.postLoginHandler = (req, res, next) ...Available Data
res.locals['@webhandle/login'] = {
loginPostUrl
, logoutUrl
}loginPostUrl : the URL that the login form should POST to
logoutURL : the URL which either GET or POST will log out the user
Login Form
Really, you can use any form you want. However, if you want to start out with something simple you can use
__::@webhandle/login/login-form__It will include all of its needed css dependencies via the external resources manager.
Error Messages
The code will add flash messages to indicate what went wrong if something went wrong.
