Socket
Socket
Sign inDemoInstall

@pmc12thsuki/session-manager

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pmc12thsuki/session-manager

## Setup `yarn add @bonio-tw/session-manager`


Version published
Maintainers
1
Install size
153 kB
Created

Readme

Source

session-manager

Setup

yarn add @bonio-tw/session-manager

How To Use

import { initSessionManager } from '@bonio-tw/session-manager';

// app or web storage
// https://developer.mozilla.org/zh-TW/docs/Web/API/Storage
const customStorage = {}; 

const sessionManager = initSessionManager({
    storage: customStorage,
});

initSessionManager 參數

  • storage:
    • required
    • 可帶 app 或 web 的 storage
    • 必須實現 getItemsetItemremoveItem 接口
  • sessionIdTTL:
    • optional
    • sessionId 過期的時間。
    • 以秒為單位,default 值為 1800 秒(30分鐘)
    • 使用 0 代表 sessionId 不會因為閒置而過期
  • generateSessionId:
    • optional
    • 產生 sessionId 的方法
    • default 使用 uuidv4
  • generateClientId:
    • optional
    • 產生 clientId 的方法
    • default 使用 uuidv4
const sessionManager = initSessionManager({
    storage: customStorage,
    sessionIdTTL: 30 // 30s
    generateSessionId: () => `mySessionId`,
    generateClientId: () => `myClientId`
});

SessionManager API

  • getSession:返回當前的 sessionIdclientId

    • 過午夜、超過 sessionIdTTL 時,會 renew sessionId
    • 可帶參數 sessionIdTTL,複寫當次 getSession 時要使用的 ttl 時間。使用 0 代表 sessionId 不會因為閒置而過期。
  • clearSession:清空當前 storage 中紀錄的 session 資訊

const session = await sessionManager.getSession({sessionIdTTL: 0});
// 不檢查是否已經超過 sessionId 的閒置時間
console.log(session)
// { sessionId: 'mySessionId', clientId: 'myClientId' }
await sessionManager.clearSession();

FAQs

Last updated on 21 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc