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

@mobixsoftwarestudio/posso

v1.1.6

Published

Posso it's a library to control permissions to routes, components and private routes.

Downloads

18

Readme

Crafted with :heart: by Mobix Software Studio to React.js applications.

Posso it's a library to control permissions to routes, components and private routes.

NPM

Install

// with npm:
npm install --save @mobixsoftwarestudio/posso

// with yarn:
yarn add @mobixsoftwarestudio/posso

Dependencies

Usage

Provider

const permissionsOfApp = ['page/home'];
const isAuthenticated = () => localStorage.getItem('exampleToken') == null;

<PossoProvider
  permissions={permissionsOfApp}
  isAuthenticated={isAuthenticated()}
  notAuthenticatedRedirect={<Redirect to="/" />} authenticatedRedirect="/home"
>
  {...}
</PossoProvider>

Route

import React from 'react';
import { Switch } from 'react-router-dom';
import { PossoRoute } from '@mobixsoftwarestudio/posso';

import Home from './screens/Home';
import Login from './screens/Login';
import Admin from './screens/Admin';

const NotAllowedComponent = () => (
  <div>
    <h2>Not allowed page.</h2>
  </div>
);

export default Routes = () => (
  <Switch>
    <PossoRoute
      exact
      path='/'
      component={Login}
    />
    <PossoRoute
      path='/home'
      exact
      isPrivate
      permissions={['page/home']}
      render={() => <Home />}
    />
    <PossoRoute
      path='/admin'
      exact
      isPrivate
      permissions={['page/admin']}
      component={Admin}
      notAllowedComponent={<NotAllowedComponent />}
    />
  </Switch>
);

Component

const AlternateView = () => (
  <h2>Show to everyone.</h2>
);

<CheckPermission
  permissions={['page/home']}
  alternateView={<AlternateView />}
>
  <span>Authorized component</span>
</CheckPermission>

API

<PossoProvider />

The component accepts the following props:

|Name|Type|Description |:--:|:-----|:-----| |isAuthenticated|boolean|isAuthenticated used to control authenticated routes. |notAuthenticatedRedirect|JSX.Element| notAuthenticatedRedirect used to render/redirect a page when user is not authorized. |authenticatedRedirect|string| authenticatedRedirect used to redirect a page when user is logged and access not private page. |permissions|string[]| permissions used to wrap all project with all permissions of user. |authorizationStrategy|func| authorizationStrategy used to define your own rule to check permissions.

<PossoRoute />

The component accepts the following props:

|Name|Type|Description |:--:|:-----|:-----| |isPrivate|boolean|Is used to refer a route that needs authentication. |notAllowedComponent|JSX.Element| It is used to show a custom component when the user is not allowed to view a specific page. |permissions|string[]| It is used to say what permissions are required to view the page./ |authorizationStrategy|func| authorizationStrategy used to define your own rule to check permissions.

<CheckPermission />

The component accepts the following props:

|Name|Type|Description |:--:|:-----|:-----| |permissions|string[]| It is used to say what permissions are required to view the component. |authorizationStrategy|func| authorizationStrategy used to define your own rule to check permissions.

License

Copyright (c) 2020 Mobix Software Studio.

Licensed under The MIT License (MIT).