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

flux-sdk-helpers

v0.1.2

Published

Helper functions for the Flux Browser SDK

Downloads

7

Readme

Flux SDK Helpers

Helper functions for the Flux Browser SDK.

  • Setup
  • Example
  • API

Notes:

  • These functions do not add any additional functionality. They're meant only to simplify some common patterns, particularly around authentication.
  • These helpers are only compatible with the browser version.
  • FluxHelpers makes some lightweight usage of window.localStorage. We namespace everything under __FLUX__. (This may change in future version)

Setup

Standard

In your HTML:

<script src="https://unpkg.com/flux-sdk-browser@<sdk version>/dist/flux-sdk-min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/flux-sdk-helpers.js"></script>

In your JavaScript:

var sdk = new FluxSdk(clientId, {
  redirectUri: 'https://example.com/auth'
});
var helpers = new FluxHelpers(sdk);

Advanced

  1. npm install --save flux-sdk-helpers
  2. Import into your code:
// ES6
import FluxHelpers from 'flux-sdk-helpers';
import FluxSdk from 'flux-sdk-browser';

// CommonJS
var FluxSdk = require('flux-sdk-browser');
var FluxHelpers = require('flux-sdk-helpers');

var sdk = new FluxSdk('YOUR_CLIENT_ID', {
  redirectUri: 'https://example.com/auth'
});
var helpers = new FluxHelpers(sdk);

Example

var sdk = new FluxSdk('YOUR_CLIENT_ID', { redirectUri: 'https://example.com/authorize' });
var helpers = new FluxHelpers(sdk);

let user = null;

function initializeUser() {
  return helpers.isLoggedIn()
    .then(function(isLoggedIn) {
      if (isLoggedIn) {
        user = helpers.getUser();
      } else {
        return helpers.login();
      }
    });
}

function initializeApp() {
  // Your app is ready to go! :)
  user.fetchProfile()
    .then(function(profile) {
      console.log(profile);
    });
}

// Because the authentication process is asynchronous,
// make sure that you wait until the user has been authenticated
// before you perform any logic that depends on the user being set!
initializeUser().then(initializeApp);

API

constructor: FluxHelpers(sdk)

Arguments

  1. sdk (FluxSdk instance): An instance of the Flux Browser SDK].

NOTE: FluxHelpers assumes that you have instantiated the SDK with your redirect URI, i.e., via new FluxSdk(clientId, { redirectUri: redirectUri }) where clientId and redirectUri are your app's client ID and redirect URI.

login(redirectUrl, replace)

This authenticates and stores a user. It is a shortcut that combines redirectToFluxLogin and storeFluxUser.

Arguments

  1. redirectUrl? (String): The location that you want your user to go to once they have been authenticated. If not supplied, this will simply redirect the user to a cleaned-up version of their current location that does not contain authentication-related values.
  2. replace (Boolean): If true, the current location's spot in your user's history will be overwritten by Flux: they will not be able to return to it by pressing "back." See Location.replace vs Location.assign for details.

Return Value

For the first login step, redirectToFluxLogin, it will return nothing as the user gets redirected.

For the second login step, storeFluxUser, it will return the same empty promise as storeFluxUser.

getUser

This returns the current user, using whatever credentials are currently stored.

Return Value

User: A Flux User instance, all set for you to go.

logout

This removes the currently stored user.

redirectToFluxLogin(replace)

redirectToFluxLogin sends a user to Flux for authentication. Upon authorizing your app, they will be redirected back to your app.

Arguments

  1. replace (Boolean): If true, the current location's spot in your user's history will be overwritten by Flux: they will not be able to return to it by pressing "back." See Location.replace vs Location.assign for details.

storeFluxUser(redirectUrl, replace)

If the user has just been redirected from authenticating on Flux, their credentials will be stored in the browser will be redirected to wherever you want them to go next.

Otherwise, storeFluxUser will resolve to an empty promise and you can continue loading your app.

Arguments

  1. redirectUrl? (String): The location that you want your user to go to once they have been authenticated. If not supplied, this will simply redirect the user to a cleaned-up version of their current location that does not contain authentication-related values.
  2. replace (Boolean): If true, the current location's spot in your user's history will be overwritten by Flux: they will not be able to return to it by pressing "back." See Location.replace vs Location.assign for details.

Return Value

Promise --> null storeFluxUser will always resolve to a Promise. You should use this to catch authentication errors (e.g., from an invalid client ID) and to continue your app's initialization logic if the user was not just redirected from authenticating on Flux.