Members
Methods
# static buildAuthenticatedRouter(admin, auth, predefinedRouteropt, sessionOptionsopt, formidableOptionsopt) → {express.Router}
Builds the Express Router which is protected by a session auth
Using the router requires you to install express-session
as a
dependency. Normally express-session holds session in memory, which is
not optimized for production usage and, in development, it causes
logging out after every page refresh (if you use nodemon).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
admin |
AdminBro | instance of AdminBro |
||
auth |
Object | authentication options |
||
authenticate |
module:@admin-bro/express.Authenticate | authenticate function |
||
cookiePassword |
String | secret used to encrypt cookies |
||
cookieName |
String | adminbro | cookie name |
|
predefinedRouter |
express.Router |
<optional> |
Express.js router |
|
sessionOptions |
SessionOptions |
<optional> |
Options that are passed to express-session |
|
formidableOptions |
ExpressFormidableOptions |
<optional> |
Options that are passed to express-session |
Express.js router
Example
const ADMIN = {
email: '[email protected]',
password: 'password',
}
AdminBroExpress.buildAuthenticatedRouter(adminBro, {
authenticate: async (email, password) => {
if (ADMIN.password === password && ADMIN.email === email) {
return ADMIN
}
return null
},
cookieName: 'adminbro',
cookiePassword: 'somePassword',
}, [router])
# static buildRouter(admin, predefinedRouteropt, formidableOptionsopt) → {express.Router}
Builds the Express Router that handles all the pages and assets
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
admin |
AdminBro | instance of AdminBro |
|
predefinedRouter |
express.Router |
<optional> |
Express.js router |
formidableOptions |
ExpressFormidableOptions |
<optional> |
Express.js router |
Express.js router
Type Definitions
# Authenticate(emailopt, passwordopt) → {CurrentAdmin|null}
function taking 2 arguments email and password
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string |
<optional> |
email given in the form |
password |
string |
<optional> |
password given in the form |
returns current admin or null