Namespace

session

kiss.session

A simple session manager

This module is 100% specific and only works in combination with KissJS server.

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 16

Members

# static maxIdleTime

Max idle time (30 minutes 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 26

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 443

this

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

# async static checkTokenValidity(autoRenewopt) → {Promise.<boolean>}

Renew the current access token if needed. If token is not valid and can"t be renewed, return false

Parameters:
Name Type Attributes Default Description
autoRenew boolean <optional>
true

If true, will try to renew the token if invalid token code (498) is received.

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

Promise.<boolean>

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

Get the user's ACL.

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

Array containing all the user names and groups (32 hex id)

Array.<string>

# static getAccountId()

Get authenticated user's account id Offline and in-memory environments are anonymous

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

# static getCollaborators()

Get all current user's accounts he collaborates with

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

# static getCurrentAccountId()

Get authenticated user's current account id Offline and in-memory environments are anonymous

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

# static getExpiration()

Get token's expiration

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

# static getFirstName()

Get authenticated user's first name

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

# static getHttpHost() → {string}

Get the Http host with protocol and port

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

The host with protocol and port

string

# static getInvitations()

Get all users pending invitations to collaborate

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

# static getLastActivity()

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

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

# static getLastName()

Get authenticated user's last name

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

# async static getNewToken()

Gets a new token from the Refresh Token

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

The token, or false if it failed

# static getRefreshToken()

Get refresh token

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

# async static getServerEnvironment() → {string}

Get the application's server runtinme environment

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

"dev" | "production" | ... | "unknown"

string

# static getToken()

Get access token

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

# static getUserId()

Get authenticated user's id

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

# static getUserName()

Get authenticated user's full name Offline and in-memory environments are anonymous

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

# static getWebsocketHost() → {string}

Get the websocket host with protocol and port

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

The host with protocol and port

string

# static getWebsocketPort()

Get websocket non-secure port

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

# static getWebsocketSSLPort()

Get websocket secure port

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

# async static init(sessionData)

Set the session params:

  • token
  • expiration date
  • accountId
  • user's id
  • user's first name
  • user's last name
  • user's account ownership
Parameters:
Name Type Description
sessionData object

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

# static initAccountManagers()

Initialize the account managers Note: a user is always an account manager for in-memory and offline mode

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

# static initAccountOwner()

Initialize the account owner Note: a user is always the account owner for in-memory and offline mode

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

# static isAccountManager()

Tell if the authenticated user is one of the account managers

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

# static isAccountOwner()

Tell if the authenticated user is the owner of the account

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

# static isAuthenticated()

Check if the user is authenticated

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

# static isIddle()

Check if the user is idle (= no mouse activity for n minutes)

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

# static isOffline()

Check if the environment is online/offline

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

# static logout()

Logout the user and redirect to the login page

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

# static reset()

Reset all kiss.session variables

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

# async static restore()

Restore session variables after a browser refresh

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

# static setDefaultViews(config)

Define the default views:

  • login: view to login
  • home: view to display after login
Parameters:
Name Type Description
config object
login string

Default = "authentication-login"

home string

Default = "home-start"

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

Example
kiss.session.setDefaultViews({
 login: "your-login-view",
 home: "your-home-view"
})

# static setHost(config)

Set the host for session requests. Host will be completed with protocol and port

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 74

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
Parameters:
Name Type Description
methods Array.<string>

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

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 265

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

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 927

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 471

The /switchAccount response

object