UNPKG

react-native-auth2.0-twitch

Version:

A lightweight React Native library for integrating Twitch OAuth 2.0 authentication using Android Custom Tabs. It allows you to securely authenticate users with Twitch by launching an external browser window (Custom Tabs) and handling the OAuth flow withou

57 lines (41 loc) 1.74 kB
# react-native-auth2.0-twitch auth 2.0 twitch ## Installation ```sh npm install react-native-auth2.0-twitch ``` ## Usage You need to create an application and get the client_id [dev.twitch](https://dev.twitch.tv/) Mandatory for [iOS Universal Link](https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content/) and [Android App Link](https://developer.android.com/training/app-links?hl=en) for redirect ```js import { useTwitchAuth } from 'react-native-auth2.0-twitch'; const { startAuth, error } = useTwitchAuth({ clientId: 'You client_id', redirectUri: 'You redirect_uri', // Optional: force the Twitch consent/login screen even if the user already authorized your app // Maps to the Twitch "force_verify" parameter. Default is false. forceVerify: false, onSuccess: (code) => { console.log('Code auth:', code); }, onError: (err) => { console.error('Error auth:', err.message); } }); ``` The result should be a code - which you can change to [access_token](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#authorization-code-grant-flow) and use it to get the user data. ### force_verify (optional) - What: When enabled, Twitch will always show the login/consent screen, even if the user already authorized your app before (equivalent to Twitch’s force_verify parameter). - Why: Useful to ensure a fresh login, prompt the user to re-consent, or let them switch accounts explicitly. - How: Set forceVerify: true in the hook options: ```js useTwitchAuth({ // ...existing options... forceVerify: true, }); ``` ## Twitch OAuth Documentation [Authentication](https://dev.twitch.tv/docs/authentication/) ## License MIT