Namespace

session

kiss.session

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

View Source client/core/modules/session.js, line 17

Members

# static host

Current host for session requests.

View Source client/core/modules/session.js, line 69

# static httpPort

Http port for session requests.

View Source client/core/modules/session.js, line 74

# static httpsPort

Https port for session requests.

View Source client/core/modules/session.js, line 79

# static isOwner

Flag (true/false) to track if the active user is the account owner.

View Source client/core/modules/session.js, line 40

# static loginMethods

Possible login methods are currently:

  • internal (email/password)
  • google
  • microsoftAD
  • microsoft365
  • linkedin
  • facebook

Default login methods are internal, google and microsoftAD

View Source client/core/modules/session.js, line 64

# 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

View Source client/core/modules/session.js, line 27

# static secure

Flag (true/false) to check the protocol security for session requests (both HTTP and Websocket).

View Source client/core/modules/session.js, line 122

# 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.

View Source client/core/modules/session.js, line 35

# static wsPort

Websocket port for session requests.

View Source client/core/modules/session.js, line 84

# static wssPort

Secure websocket port for session requests.

View Source client/core/modules/session.js, line 89

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()

View Source client/core/modules/session.js, line 637

this

Example
kiss.session.addHook("afterInit", function(sessionData) {
 console.log("The session data is...", sessionData)
})

# static getACL() → {Array.<string>}

Get the user's ACL.

View Source client/core/modules/session.js, line 1121

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.

View Source client/core/modules/session.js, line 490

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.

View Source client/core/modules/session.js, line 510

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.

View Source client/core/modules/session.js, line 501

The current account id

string

# static getFirstName() → {string}

Get authenticated user's first name.

Returns "anonymous" in offline and memory mode.

View Source client/core/modules/session.js, line 463

The user's first name

string

# static getHttpHost() → {string}

Get the Http host with protocol and port

View Source client/core/modules/session.js, line 147

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.

View Source client/core/modules/session.js, line 526

Array of account ids

Array.<string>

# static getLastActivity() → {date}

Get the date/time of the last user activity which was tracked

View Source client/core/modules/session.js, line 434

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.

View Source client/core/modules/session.js, line 472

The user's last name

string

# static getMaxIdleTime() → {number}

Get the maximum idle time before automatically logging out the user

View Source client/core/modules/session.js, line 337

The maximum idle time in minutes

number

# static getUserId() → {string}

Get authenticated user's id.

Returns "anonymous" in offline and memory mode.

View Source client/core/modules/session.js, line 447

The user id

string

# static getUserName() → {string}

Get authenticated user's full name.

Returns "anonymous" in offline and memory mode.

View Source client/core/modules/session.js, line 481

The user's full name

string

# static getWebsocketHost() → {string}

Get the websocket host with protocol and port

View Source client/core/modules/session.js, line 161

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.

View Source client/core/modules/session.js, line 551

true if the user is an account manager

boolean

# static isAccountOwner() → {boolean}

Tell if the authenticated user is the owner of the account

View Source client/core/modules/session.js, line 540

true if the user is the account owner

boolean

# static isAuthenticated() → {boolean}

Check if the user is authenticated

View Source client/core/modules/session.js, line 454

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().

View Source client/core/modules/session.js, line 1108

# static isOffline() → {boolean}

Check if the environment is offline

View Source client/core/modules/session.js, line 310

true if the environment is offline

boolean

# static isOnline() → {boolean}

Check if the environment is online

View Source client/core/modules/session.js, line 317

true if the environment is online

boolean

# static logout()

Logout the user and redirect to the login page

View Source client/core/modules/session.js, line 1241

# static reset()

Reset all kiss.session variables

View Source client/core/modules/session.js, line 1048

# async static restore()

Restore session variables (typically after a browser refresh).

View Source client/core/modules/session.js, line 991

# static selectMaxIdleTime()

Display a window to set the maximum idle time before automatically logging out the user

View Source client/core/modules/session.js, line 344

# 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"

View Source client/core/modules/session.js, line 187

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>

View Source client/core/modules/session.js, line 110

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
  • google
  • microsoftAD
  • microsoft365
  • linkedin
  • facebook

Default login methods are internal, google and microsoftAD

Parameters:
Name Type Description
methods Array.<string>

View Source client/core/modules/session.js, line 283

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

View Source client/core/modules/session.js, line 327

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

View Source client/core/modules/session.js, line 135

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.

View Source client/core/modules/session.js, line 1136

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

View Source client/core/modules/session.js, line 665

The /switchAccount response

object