Enable user authentication, defaults to disabled (false).
The session store instance, defaults to a new MemoryStore(memory) instance.
Optional
cookie_The name of the session ID cookie to set in the response (and read from in the request). The default value is 'connect.sid'.
Optional
cookie_Specifies the boolean value for the Secure Set-Cookie attribute. The default is true, which sets the Secure attribute on the cookie.
Optional
cookie_Specifies the boolean value for the HttpOnly Set-Cookie attribute. Defaults to true, which sets the HttpOnly attribute on the cookie.
Optional
redis_If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server. For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379". To connect to a different host or port, use a connection string in the format "redis[s]://[[username][:password]@][host][:port][/db-number]". For example, "redis://alice:foobared@awesome.redis.server:6380".
Authentication user ID field name, defaults to username
.
Authentication password field name, defaults to password
.
URL to redirect after successful authentication, defaults to /
.
URL to redirect after log off, defaults to /login
.
// Set the URL to redirect to in case of login failure as a string.
failure_redirect: '/login',
// Dynamically set the url to redirect to on login failure.
failure_redirect: (req, res) => {
// If the role stored in the cookie is admin, redirect to the admin login screen.
return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
},
This hook is called when authenticating a user. Please find the user information that owns the credentials based on the user name and password you received and return it. If the user who owns the credentials cannot be found, return null. Note that the user information must include an ID value that can identify the user.
This hook is called when user authentication is successful. Please search and return the authenticated user information to be set in the session based on the user ID of the parameter. The returned data will be set in the req.user property and the view's session variable.
URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
User authentication configuration interface using Passport.js. Defines configuration for user authentication, session management, and security settings.
See
Passport.js
Example