npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@schibsted/react-account

v1.8.1

Published

React Context Provider and Hook making it easier to use Schibsted Account in your React app

Downloads

37

Readme

Schibsted Account for React

A React Context Provider and Hook making it easier to use Schibsted Account in your React app.

release version downloads

Installation

npm install @schibsted/react-account

Demo

AccountProvider

First, wrap your app (or parts of it) in the AccountProvider:

// App.js

import { AccountProvider } from "@schibsted/react-account";

const config = {
  identity: {
    clientId: "1234567890abcdef12345678",
    sessionDomain: "https://id.site.com",
    redirectUri: "https://site.com",
    env: "PRE",
  },
};

export default function App() {
  return (
    <AccountProvider config={config}>
      <h1>Hello, World!</h1>
    </AccountProvider>
  );
}

UseAccount

Now, you can use the useAccount hook to access what's returned from the AccountContext in any components that's wrapped by the AccountProvider:

import { useAccount } from "@schibsted/react-account";

export default function MyPage() {
    const {user, login, logout} = useAccount();

    if (!user) {
        return <button onClick={login}>Log in</button>
    }

    return (
        <h1>You are logged in as {user.displayName}</h1>
        <button onClick={logout}>Log out</button>
    );
}

Configuration

As seen in the example above, the AccountProvider expects a configuration object – as described in Schibsted Account SDK Browser.

Example

const config = {
  identity: {
    clientId: "1234567890abcdef12345678",
    sessionDomain: "https://id.site.com",
    redirectUri: "https://site.com",
    env: "PRE",
  },
};

Varnish Paywall Cookie

In order to set the Varnish Paywall Cookie, also known as SP_ID, your config should contain the optional varnish field.

const config = {
  identity: {
    ...
  },
  varnish: {
    domain: 'site.com', // Top level domain for your site
    expiresIn: 86400,
  }
};

Access restriction check

In order to check if the logged in user has access to your subscription products, your config should contain your source (i.e. the publisher), your product ids and optionally the access-domain (defaults to access.schibsted.digital).

const config = {
  identity: {
    ...
  },
  access: {
    pids: ['abc123', 'def456'],
    source: 'vg.no',
    domain: 'access.your.domain'
  }
};

Contributing

Everyone is welcome to contribute to this repository. Feel free to create issues or to submit Pull Requests.

Releasing

This repository uses Github Actions and Semantic Release to release new versions to NPM. The release script is every push to the main branch.

A commit message starting with feat: will release a new minor version of the package, while a commit message starting with fix: will release a new patch version.

Commit messages containing BREAKING CHANGE in the commit footer will release a new major version.

For commits that should not trigger the release script to run, start your commit message with chore:, or add [skip ci] to the body of your commit message.