Socket
Socket
Sign inDemoInstall

svelte-session-manager

Package Overview
Dependencies
0
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svelte-session-manager

Session store for svelte (currently only for JWT)


Version published
Weekly downloads
867
decreased by-4.41%
Maintainers
1
Install size
13.3 kB
Created
Weekly downloads
 

Readme

Source

Svelte v3 npm License minified size downloads semantic-release

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 backing 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 or localStorage token is still valid


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

The test runs the following requests against the server

  • successful auth
curl -X POST -d '{"username":"user","password":"secret"}' 'http://[::]:5000/api/login'
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbnRpdGxlbWVudHMiOiJhLGIsYyIsImlhdCI6MTYwNDY2NDI0NywiZXhwIjoxNjA0NjY0MjYyfQ.qyjeoCuXO0iyYwSxM2sM02_BVhaZobRmEWam1M8Hzkx51nbsAuTR8G1rNgz1COo_KvbCU7LwZt7qnSEFB1tcwyDA1eBxwc2Wb7JxWgQ50m1IWkr2JCgY1seWRJRcwZBXiTRtiPqhzofP-l3S-CBluzU48cd4yzoPayczLkKuPK4"}
  • invalid credentials
curl -X POST -d '{"username":"user","password":"wrong"}' 'http://[::]:5000/api/login'
{"message":"Unauthorized"}

API

Table of Contents

install

With npm do:

npm install svelte-session-manager

license

BSD-2-Clause

Keywords

FAQs

Last updated on 08 Nov 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