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

graphiql-auth-token

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphiql-auth-token

A React subclass of GraphiQL allowing you to add an authentication token from the user interface.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
Maintainers
1
Weekly downloads
 
Created
Source

GraphiQL-Auth-Token

License

A React subclass of GraphiQL allowing you to add an authentication token from the user interface.

Getting started

npm install --save graphiql-auth-token

Alternatively, if you are using yarn:

yarn add graphiql-auth-token

GraphiQLAuthToken offers the same properties as GraphiQL as it is its subclass. It just requires one more (mandatory) property: onTokenUpdate - a callback function that will be called whenever the user enter / update the auth token. You can use it to store the token and include it inside the fetcher.

import React from 'react';
import ReactDOM from 'react-dom';
import GraphiQL from 'graphiql-auth-token';
import fetch from 'isomorphic-fetch';

let token =  null,

const graphQLFetcher = (graphQLParams) => {
    const headers = { 'Content-Type': 'application/json' }
    if (token){
        headers['Authentication'] = 'Bearer ' + token;
    }
    return fetch(window.location.origin + '/graphql', {
        method: 'post',
        headers,
        body: JSON.stringify(graphQLParams),
    }).then(response => response.json());
}

const onTokenUpdate = (newToken) => token = newToken;

ReactDOM.render(<GraphiQLAuthToken fetcher={graphQLFetcher} onTokenUpdate={onTokenUpdate}/>, document.body);

To know the rest of the properties available, please refer to GraphiQL documentation.

Keywords

FAQs

Package last updated on 01 Dec 2019

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