Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@8base/auth

Package Overview
Dependencies
Maintainers
2
Versions
223
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@8base/auth

The 8base Auth package contains provider with authentication state and auth helpers.

  • 0.4.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
607
increased by16.51%
Maintainers
2
Weekly downloads
 
Created
Source

8base Auth

The 8base Auth package contains provider with authentication state and auth helpers.

AuthProvider

Table of Contents
  • AuthProvider
  • AuthContextProps
  • withAuth

AuthProvider

Extends Component

Provides access to the authentication state.

AuthContextProps

Authentication context

Properties
  • isAuthorized boolean?
  • authState AuthState?
  • setAuthState function (AuthState): void?

withAuth

Hoc to pass auth state to the component

Parameters
  • WrappedComponent React$ComponentType<any>
  • auth AuthContextProps Auth state passed by the props.

Returns React$ComponentType<InputProps>

Usage

Simple Usage

import { AuthProvider, AuthConsumer } from '@8base/auth';

  <AuthProvider>
    ...
      <AuthConsumer>
        {
          (auth: AuthContextProps) => (<div />)
        }
      </AuthConsumer>
    ...  
  </AuthProvider>

Usage with @8base/apollo-client

import React, { Component } from 'react';
import { withAuth } from '@8base/auth-provider';
import { EightBaseApolloClient } from '@8base/apollo-client';
import { ApolloProvider } from 'react-apollo';

class Foo extends Component {
  constructor(props) {
    super(props);

    this.client = createApolloClient({
      getAuthState: this.getAuthState,
      getRefreshTokenParameters: this.getRefreshTokenParameters,
      onAuthSuccess: this.onAuthSuccess,
      onAuthError: this.onAuthError,
      uri: process.env.REACT_APP_SERVER_URL
    });
  }

  getRefreshTokenParameters = () => {
    const { auth: { authState: { email, refreshToken }}} = this.props;

    return { email, refreshToken };
  };

  onAuthSuccess = ({ refreshToken, idToken }) => {
    const { auth: { setAuthState }} = this.props;

    setAuthState({
      idToken,
      refreshToken,
    });
  };

  onAuthError = (err) => {
    const { auth: { setAuthState }} = this.props;

    setAuthState({
      idToken: '',
      refreshToken: '',
    });
  };

  getAuthState = () => {
    const { auth: { authState: { idToken, workspaceId }}} = this.props;

    return {
      idToken,
      workspaceId,
    };
  };

  render() {
    const { children } = this.props;

    return (
      <ApolloProvider client={ this.client } >
        <div />
      </ApolloProvider>
    );
  }
}

Foo = withAuth(Foo);

FAQs

Package last updated on 22 Oct 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc