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

@lushdigital/auth

v4.1.6

Published

Auth package for Lush apps. Uses context and GraphQL

Downloads

17

Readme

Contents

Introduction

The Lush applications are all using two cookies for handling user sessions and auth so this package assumes the presence of jwt and user cookies. To use the package simply run:

$ yarn add @lushdigital/auth

Auth Context

To document still

AuthWrapper

The AuthWrapper is a simple component that can be used in the app to show or hide content based on whether a user is logged in or not and has certain permissions. It takes two props: -

  • a bool for authenticated. When this is set to false it will only render its children if there is no logged in user. By default it is true and will only render its children if there is a logged in user.
  • an array for permissions which is empty by default. If a user is logged in and a permissions array is passed to the component then the provider will compare those two arrays (expects int or string values within) and return the children to the user if they have adequate permissions. Currently this function uses the mock roles array set by the login action but could be modified to check whatever is needed. n.b. if authenticate is false then the permission check will not be run as the component assumes only logged in users have permissions
<AuthWrapper authenticated={ false }>
	// ... my components requiring people not to be logged in
</AuthWrapper>
<AuthWrapper permissions={ [2, 3] }>
	// ... my components requiring permissions
</AuthWrapper>

AuthRoute

The AuthRoute component is a permissioned based wrapper for React router 4. The component takes a number of required props.

Basic example

The below example will render a basic route which requires a user to be logged in (it gets this data from the AuthProvider).

<AuthRoute
  path='/my-route'
  componentProps={ props }
  title='pagetitle'
  component={ Component }
/>

Permissioned route

You can also enforce permission checks by passing an array of grants at the component as per the following (n.b. you will need to configure the AuthProvider to support this in your specific application):

<AuthRoute
  path='/my-route'
  componentProps={ props }
  title='pagetitle'
  component={ Component }
  permissions={ [1,2,3] }
/>

Logged out route

You can also require users to not be logged in to see certain routes (e.g. login or register routes). Simply pass authenticated={ false } & notAuthenticated={ true } as per the following:

<AuthRoute
  path='/my-route'
  componentProps={ props }
  title='pagetitle'
  component={ Component }
  authenticated={ false }
  notAuthenticated={ true }
/>

Standard route

To simplify your route rendering you can also use this component to render standard routes. Simply pass authenticated={ false } as per the following:

<AuthRoute
  path='/my-route'
  componentProps={ props }
  title='pagetitle'
  component={ Component }
  authenticated={ false }
/>

Other props

  • redirect: String - Where a component should redirect if user can't access (default is 404 or if user not logged in it will default to login)
  • exact: Bool - exact param for route, defaul is true
  • language: String - langauge to replace any :language params in redirect route
  • ignoreScrollBehavior: Bool - default false