šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

svelte-session-manager

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-session-manager

Session store for svelte (currently only for JWT)

1.0.1
Source
npm
Version published
Weekly downloads
502
13.83%
Maintainers
1
Weekly downloads
Ā 
Created
Source

Build Status codecov.io Commitizen friendly Coverage Status Dependency Status devDependency Status docs downloads GitHub Issues Greenkeeper Known Vulnerabilities minified size npm semantic-release styled with prettier

svelte-session-manager

Session store for svelte (currently only for JWT)

usage

import { derived } from 'svelte';
import { Session, login } from 'svelte-session-manager';

// use localStorage as backng store
let session = new Session(localStorage);

// session may still be valid
if(!session.isValid) {
  await login(session, 'https://mydomain.com/authenticate', 'a user', 'a secret');
}

session.isValid; // true when auth was ok


export const values = derived(
  session,
  ($session, set) => {
    if (!session.isValid) {
      set([]); // session has expired no more data
    } else {
      fetch('https://mydomain.com/values', {
        headers: {
          ...session.authorizationHeader
        }
      }).then(async data => set(await data.json()));
    }
    return () => {};
  }
);

// $values contains fetch result as long as session has not expired

run tests

export BROWSER=safari|chrome|...
npm|yarn test

API

Table of Contents

SessionData

Data as preserved in the backing store

Type: Object

Properties

  • username string user name (id)
  • access_token string JWT token

Session

User session To create as session backed by browser local storage

let session = new Session(localStorage);

Parameters

Properties

save

persist into the packing store

authorizationHeader

http header suitable for fetch

isValid

As long as the expirationTimer is running we must be valid

Returns boolean true if session is valid (not expired)

invalidate

remove all tokens from the session and the backing store

subscribe

Fired when the session changes

Parameters

login

Bring session into the valid state by callinf the authorization endpoint and asking for a access_token

Parameters

  • session Session to be opened
  • endpoint string authorization url
  • username string id of the user
  • password string user credentials

install

With npm do:

npm install svelte-session-manager

license

BSD-2-Clause

Keywords

svelte

FAQs

Package last updated on 05 Oct 2019

Did you know?

Socket

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