# comfytwitch

> Comfiest Way to Add Serverless Twitch Authentication

Latest version **1.0.7** (published 2024-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install comfytwitch
pnpm add comfytwitch
yarn add comfytwitch
bun add comfytwitch
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2024-03-27 |
| First published | 2020-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Instafluff |
| Maintainers | instafluff |
| Keywords | Instafluff, Comfy, Twitch, Auth, Authentication, Serverless, Web, OAuth, Implicit |

## Links

- npm: https://www.npmjs.com/package/comfytwitch
- Repository: https://github.com/instafluff/ComfyTwitch
- Homepage: https://github.com/instafluff/ComfyTwitch#readme
- Issues: https://github.com/instafluff/ComfyTwitch/issues
- npm.io page: https://npm.io/package/comfytwitch

## Dependencies (1)

- [webwebweb](https://npm.io/package/webwebweb.md) ^1.1.10

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2024-03-27
- 1.0.6 — 2022-10-22
- 1.0.5 — 2022-10-22
- 1.0.4 — 2022-10-22
- 1.0.3 — 2022-10-22
- 1.0.2 — 2020-07-03
- 1.0.1 — 2020-07-03
- 1.0.0 — 2020-07-03

## README

# ComfyTwitch
Comfiest Way to Add Serverless Twitch Authentication

**ComfyTwitch** lets you integrate Twitch authentication for websites without a server ***SUPER EASILY*** in just a few lines of code. It automatically caches the authentication in the browser so that users do not have to log in every single visit.

## Instafluff ##
> *Like these projects? The best way to support my open-source projects is by becoming a Comfy Sponsor on GitHub!*

> https://github.com/sponsors/instafluff

> *Come and hang out with us at the Comfiest Corner on Twitch!*

> https://twitch.tv/instafluff

## Demo ##
To see how it works, check out this static webpage that authenticates using Twitch OAuth: [https://www.instafluff.tv/ComfyTwitch](https://www.instafluff.tv/ComfyTwitch)

## Instructions ##

#### Prequisites
1. Create a Twitch application from [https://dev.twitch.tv/console/apps/create](https://dev.twitch.tv/console/apps/create) to generate a Twitch Client ID

2. Add an OAuth Redirect URL to your Twitch application for the authentication to redirect the user to afterwards. A local example would look like: `http://localhost:8800/index.html`

#### Website

1. Download  `comfytwitch.min.js` from the `web` folder or include from the JSDeliver CDN and add into every page you need authenticated:
```javascript
<script src="comfytwitch.min.js"></script>
```

OR

```javascript
<script src="https://cdn.jsdelivr.net/npm/comfytwitch@latest/web/comfytwitch.min.js"></script>
```

2. Check for Twitch authentication using `ComfyTwitch.Check()` for whether or not the user is logged in.
***The authentication is cached in the browser so that the user does not have to log in every time.***
```html
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/comfytwitch@latest/web/comfytwitch.min.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            const clientId = "YOUR-CLIENT-ID";
            const baseUrl = window.location.origin;

            ComfyTwitch.Check()
            .then( result => {
                if( result ) {
                    // Logged In
                }
                else {
                    // Logged Out
                }
            });
        </script>
    </body>
</html>
```

3. Add Twitch Log-In by calling `ComfyTwitch.Login()` on a button click or through a separate page, passing in the Client ID, the same Redirect URI as set in your Twitch application, and the [Twitch Permission Scopes](https://dev.twitch.tv/docs/authentication/#scopes) you need:
```javascript
ComfyTwitch.Login( "YOUR-CLIENT-ID", `http://localhost:8800/index.html`, [ "user:read:email" ] );
```

4. Add Twitch Log-out by calling `ComfyTwitch.Logout()`

## Additional Functions ##

 - **GetUser**`( clientId, userId )`
    - Retrieve a Twitch user's information
```javascript
let user = await ComfyTwitch.GetUser( "YOUR-CLIENT-ID", "TWITCH-USER-ID" );
```

---
_Source: https://npm.io/package/comfytwitch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
