Skip to content

weixin-ts / bot/src / SessionStorage

Interface: SessionStorage

Defined in: bot/src/auth/session.ts:44

Runtime-agnostic session storage interface.

Implement this for localStorage, IndexedDB, Redis, files, KV stores, etc.

Example

ts
import type { SessionStorage } from '@weixin-ts/bot'

const storage: SessionStorage = {
  async load() {
    const raw = localStorage.getItem('weixin-session')
    return raw ? JSON.parse(raw) : null
  },
  async save(data) {
    localStorage.setItem('weixin-session', JSON.stringify(data))
  },
  async delete() {
    const had = localStorage.getItem('weixin-session') !== null
    localStorage.removeItem('weixin-session')
    return had
  },
}

Properties

delete

delete: () => Promise<boolean>

Defined in: bot/src/auth/session.ts:50

Delete session data. Return true if something was deleted.

Returns

Promise<boolean>


load

load: () => Promise<SessionData | null>

Defined in: bot/src/auth/session.ts:46

Load saved session data. Return null if nothing is stored.

Returns

Promise<SessionData | null>


save

save: (data) => Promise<void>

Defined in: bot/src/auth/session.ts:48

Save session data.

Parameters

data

SessionData

Returns

Promise<void>

Released under the MIT License.