Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-twitch-ext-onauthorized with all npm packages installed. Try it out:

var reactTwitchExtOnauthorized = require("react-twitch-ext-onauthorized")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-twitch-ext-onauthorized v2.0.1

React hook handling authorization with Twitch Extensions JavaScript Helper


Travis Build Status AppVeyor Build status Maintainability Test Coverage Greenkeeper badge

React hook performing authorization with Twitch Extensions JavaScript Helper. It calls twitch.ext.onAuthorized and returns authorization object.

While onAuthorized is not the only method offered by The Extensions JavaScript Helper, it is one of the most important building blocks of each Twitch Extension.


npm install --save react-twitch-ext-onauthorized



import useTwitchAuth from 'react-twitch-ext-onauthorized';

const MyElement = () => {
  const twitchAuth = useTwitchAuth();
  return (
    <div>TestElement {JSON.stringify(twitchAuth)}</div>

When authorization succeeds, twitchAuth contains the following properties:

  authorized: true,
  channelId: 'channel id goes here',
  clientId: 'client id goes here',
  token: 'token goes here',
  userId: 'user id goes here',

When loaded outside of Twitch context, twitchAuth properties contain empty strings and authorized property will remain false:

  authorized: false,
  channelId: '',
  clientId: '',
  token: '',
  userId: '',

Note that you still have to provide Twitch JavaScript Helper yourself so that window.Twitch.ext resolves correctly -- see Twitch docs on adding the Extension Helper.


react-twitch-ext-onauthorized exposes two interfaces which can be used for type checking: TwitchAuthResponse and TwitchAuthObject.

To import them into your project add

import { TwitchAuthResponse } from 'react-twitch-ext-onauthorized';

// OR

import { TwitchAuthObject } from 'react-twitch-ext-onauthorized';


Represents the shape of authorization object received from Twitch.

interface TwitchAuthResponse {
  channelId: string;
  clientId: string;
  token: string;
  userId: string;


Contains Twitch authorization object (TwitchAuthResponse) and a property authorized which denotes whether authorization was successful:

interface TwitchAuthObject {
  authorized: boolean;
  channelId: string;
  clientId: string;
  token: string;
  userId: string;


Code is available under MIT license. See LICENSE for more information.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free