Coder Social home page Coder Social logo

lwojcik / react-twitch-ext-onauthorized Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 488 KB

React hook performing authorization with Twitch Extensions JavaScript Helper

License: The Unlicense

TypeScript 63.30% JavaScript 35.27% Shell 1.43%
react twitch twitchtv twitch-extensions onauthorized twitch-extension authorization hook hooks react-hooks

react-twitch-ext-onauthorized's Introduction

react-twitch-ext-onauthorized

As of 15 March 2023 this project is no longer updated or maintained.

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.

Install

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

Usage

Example:

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.

TypeScript

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";

TwitchAuthResponse

Represents the shape of authorization object received from Twitch.

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

TwitchAuthObject

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;
}

Contributions

Contributions of any kind are welcome.

You can contribute to React-twitch-ext-onauthorized by:

  • submiting bug reports or feature suggestions
  • improving documentation
  • submitting pull requests

Before contributing be sure to read Contributing Guidelines and Code of Conduct.

Contributors

To all who contribute code, improve documentation, submit issues or feature requests - thank you for making Twitch-ebs-tools even better!

We maintain an AUTHORS file where we keep a list of all project contributors. Please consider adding your name there with your next PR.

License

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

Legal

This project is not authored, affiliated or endorsed in any way by Twitch.tv.

react-twitch-ext-onauthorized's People

Contributors

greenkeeper[bot] avatar lwojcik avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

caioaugustoo

react-twitch-ext-onauthorized's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.