47ng/session-keystore

It doesn't work as expected

Closed this issue · 2 comments

Hi,

I was trying the package but it doesn't work as expected.

How can i call the session storage in another page ? I mean, i created the session storage in the login page to save the private key, but i want to call it in the dashboard page.

Hi, it depends on your setup, the SessionKeystore instance keeps its secrets in memory, so as long as it's available on both pages, you should be able to access it.

You should probably define it in another file, and access it from both pages:

// keystore.ts
import { SessionKeystore } from 'session-keystore'

export const keystore = new SessionKeystore()
// login.ts
import { keystore } from './keystore'

function login() {
  keystore.set('key', 'supersecret')
}
// dashboard.ts
import { keystore } from './keystore'

function doSomethingWithTheKey() {
  const key = keystore.get('key')
  // ...
}

Note: session-keystore does not work across tabs or windows, if that's a use-case you need, you can look into local-state-sync that I just (pre)published.