Session manager
This module is 100% specific and only works in combination with KissJS server. KissJS server is not open source yet, but you can contact us (sales@pickaform.com) for a licence.
Dependencies:
- kiss.ajax, to send credentials to the server
- kiss.views, to popup the login window
- kiss.router, to route to the right application view if session is valid
- kiss.websocket, to init the connection, to check that it's alive and reconnect if not
Members
# static host
Current host for session requests.
# static httpPort
Http port for session requests.
# static httpsPort
Https port for session requests.
# static isOwner
Flag (true/false) to track if the active user is the account owner.
# static loginMethods
Possible login methods are currently:
- internal (email/password)
- microsoftAD
- microsoft365
Default login methods are internal, google and microsoftAD
# static maxIdleTime
Max idle time, in minutes (4 hours by default). After that delay, the user is logged out and its tokens are deleted from localStorage
# static secure
Flag (true/false) to check the protocol security for session requests (both HTTP and Websocket).
# static userId
The user id. By default, before authenticating, the user is "anonymous". Once logged in, the user id is the email used to authenticate. Always "anonymous" in offline and memory mode.
# static wsPort
Websocket port for session requests.
# static wssPort
Secure websocket port for session requests.
Methods
# static addHook(event, callback)
Add a hook to perform an action before or after the session initialization
Parameters:
Name | Type | Description |
---|---|---|
event |
string
|
"beforeInit" | "afterInit" | "beforeRestore" | "afterRestore" |
callback |
function
|
Function to execute. It receives the following parameters: *beforeInit(sessionData), *afterInit(sessionData), *beforeRestore(), *afterRestore() |
this
Example
kiss.session.addHook("afterInit", function(sessionData) {
console.log("The session data is...", sessionData)
})
# static getACL() → {Array.<string>}
Get the user's ACL.
Array containing all the user names and groups (32 hex id) by which the user is recognized to access the data.
Array.<string>
# static getAccountId() → {string}
Get authenticated user's account id.
Returns "anonymous" in offline and memory mode.
The account id
string
# static getCollaborators() → {Array.<string>}
Get all current user's accounts he collaborates with.
Returns an empty array in offline and memory mode.
Array of account ids
Array.<string>
# static getCurrentAccountId() → {string}
Get authenticated user's current account id. KissJS allows a mechanism to switch from one account to another. The current account id is the one the user is currently working on.
Returns "anonymous" in offline and memory mode.
The current account id
string
# static getFirstName() → {string}
Get authenticated user's first name.
Returns "anonymous" in offline and memory mode.
The user's first name
string
# static getHttpHost() → {string}
Get the Http host with protocol and port
The host with protocol and port
string
Example
kiss.session.getHttpHost() // "https://your-host.com:443"
# static getInvitations() → {Array.<string>}
Get all the user pending invitations to collaborate with.
Returns an empty array in offline and memory mode.
Array of account ids
Array.<string>
# static getLastActivity() → {date}
Get the date/time of the last user activity which was tracked
The date/time of the last user activity
date
# static getLastName() → {string}
Get authenticated user's last name.
Returns "anonymous" in offline and memory mode.
The user's last name
string
# static getMaxIdleTime() → {number}
Get the maximum idle time before automatically logging out the user
The maximum idle time in minutes
number
# static getUserId() → {string}
Get authenticated user's id.
Returns "anonymous" in offline and memory mode.
The user id
string
# static getUserName() → {string}
Get authenticated user's full name.
Returns "anonymous" in offline and memory mode.
The user's full name
string
# static getWebsocketHost() → {string}
Get the websocket host with protocol and port
The host with protocol and port
string
Example
kiss.session.getWebsocketHost() // "wss://your-host.com:443"
# static isAccountManager() → {boolean}
Tell if the authenticated user is one of the account managers. An account manager is a user who has been promoted to manage the account like the owner.
true if the user is an account manager
boolean
# static isAccountOwner() → {boolean}
Tell if the authenticated user is the owner of the account
true if the user is the account owner
boolean
# static isAuthenticated() → {boolean}
Check if the user is authenticated
true if the user is authenticated
boolean
# static isIddle()
Check if the user is idle (= no activity for n minutes).
Set the idle threshold with setMaxIdleTime().
# static isOffline() → {boolean}
Check if the environment is offline
true if the environment is offline
boolean
# static isOnline() → {boolean}
Check if the environment is online
true if the environment is online
boolean
# static logout()
Logout the user and redirect to the login page
# static reset()
Reset all kiss.session variables
# async static restore()
Restore session variables (typically after a browser refresh).
# static selectMaxIdleTime()
Display a window to set the maximum idle time before automatically logging out the user
# static setDefaultViews(config)
Define the default views:
- login: view to login
- home: view to display after login
It allows KissJS to display the right login view and the right home view after login. Defaults are:
- login: "authentication-login"
- home: "home-start"
Parameters:
Name | Type | Description |
---|---|---|
config |
object
|
|
login |
string
|
Default = "authentication-login" |
home |
string
|
Default = "home-start" |
Example
kiss.session.setDefaultViews({
login: "your-login-view",
home: "your-home-view"
})
# static setHost(config)
Set the hosts and ports for session requests.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
object
|
||
host |
string
|
<optional> |
|
httpPort |
number
|
<optional> |
|
httpsPort |
number
|
<optional> |
|
wsPort |
number
|
<optional> |
|
wssPort |
number
|
<optional> |
Example
kiss.session.setHost({
host: "your-host.com",
httpPort: 3000,
httpsPort: 4000,
wsPort: 3000,
wssPort: 4000
})
# static setLoginMethods(methods)
Set the possible login methods.
Possible login methods are currently:
- internal
- microsoftAD
- microsoft365
Default login methods are internal, google and microsoftAD
Parameters:
Name | Type | Description |
---|---|---|
methods |
Array.<string>
|
Example
kiss.session.setLoginMethods(["internal", "google"])
# static setMaxIdleTime(newIdleTime)
Set the maximum idle time before automatically logging out the user
Parameters:
Name | Type | Description |
---|---|---|
newIdleTime |
number
|
Max idle time in minutes |
Example
kiss.session.setMaxIdleTime(60) // 1 hour
# static setSecure(host)
Set the protocol security for session requests. If true (default):
- will use "https" for HTTP
- will use "wss" for Websocket
Parameters:
Name | Type | Description |
---|---|---|
host |
string
|
Example
kiss.session.setSecure(true)
# static showLogin(redirectoopt)
Show the login prompt
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
redirecto |
object
|
<optional> |
Route to execute after login, following kiss.router convention. Route to the home page by default. |
Example
kiss.session.showLogin({
ui: "form-view",
modelId: "0183b2a8-cfb4-70ec-9c14-75d215c5e635",
recordId: "0183b2a8-d08a-7067-b400-c110194da391"
})
# async static switchAccount(accountId) → {object}
Switch the user from one account to another.
Parameters:
Name | Type | Description |
---|---|---|
accountId |
The /switchAccount response
object