Skip to content

Add an OAuth provider for Twitch #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

Nachwahl
Copy link

@Nachwahl Nachwahl commented Jun 25, 2025

Important

Add Twitch as a new OAuth provider, updating backend logic and UI components to support Twitch authentication.

  • Behavior:
    • Add TwitchProvider class in providers/twitch.tsx to handle OAuth with Twitch, including user info post-processing.
    • Update _providers in index.tsx to include TwitchProvider.
    • Add TWITCH to StandardOAuthProviderType enum in schema.prisma.
  • UI Components:
    • Add Twitch icon and color in brand-icons.tsx and BRAND_COLORS.
    • Update ProviderIcon, ProviderSettingDialog, and OAuthButton to support Twitch in providers.tsx and oauth-button.tsx.
  • Misc:
    • Add twitch to standardProviders in oauth.tsx.

This description was created by Ellipsis for 08c0de5. You can customize this summary. It will automatically update as commits are pushed.

@CLAassistant
Copy link

CLAassistant commented Jun 25, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

vercel bot commented Jun 25, 2025

@Nachwahl is attempting to deploy a commit to the Stack Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

recurseml bot commented Jun 25, 2025

⚠️ Only 5 files will be analyzed due to processing limits.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Added Twitch OAuth provider integration across the stack with UI components and backend support.

  • Potential security concern in apps/backend/src/oauth/providers/twitch.tsx needs attention for proper error handling and data validation
  • Uses Plain Object for response handling in Twitch provider instead of Map, consider using Map to prevent prototype pollution (see postProcessUserInfo method)
  • New Twitch provider follows consistent pattern with existing OAuth providers but needs additional validation
  • Added brand-consistent purple (#9146FF) Twitch icon implementation in packages/stack-ui/src/components/brand-icons.tsx
  • Standardized OAuth provider type with 'TWITCH' enum in Prisma schema for database consistency

7 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

"Client-Id": this.oauthClient.client_id as string,
},
}).then((res) => res.json());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Remove extra blank line.

Suggested change
}).then((res) => res.json());
const userInfo = info.data?.[0];

@@ -215,4 +273,5 @@ export const BRAND_COLORS: Record<string, string> = {
linkedin: '#0A66C2',
x: '#000000',
apple: '#000000',
twitch: '#ffffff'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The twitch brand color should be '#9146FF' to match the official Twitch purple used in the icon

@@ -17,6 +17,7 @@ import { MicrosoftProvider } from "./providers/microsoft";
import { MockProvider } from "./providers/mock";
import { SpotifyProvider } from "./providers/spotify";
import { XProvider } from "./providers/x";
import { TwitchProvider } from "./providers/twitch";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of TwitchProvider might not be fully compatible with the OAuth provider system. While the provider file exists and extends OAuthBaseProvider, it has not implemented the required static 'create' method that is used in the getProvider() function. This will cause runtime errors when trying to initialize the Twitch provider through getProvider().


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

}).then((res) => res.json());


const userInfo = info.data?.[0];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe access of user info properties. While info.data is checked with optional chaining (?.), the code proceeds to access properties of userInfo without verifying its existence. If the API response is malformed or empty, accessing properties like userInfo.id will cause runtime errors. Should add validation like: if (!userInfo) { throw new Error('Failed to get user info from Twitch response'); }


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

@@ -1,4 +1,4 @@
export const standardProviders = ["google", "github", "microsoft", "spotify", "facebook", "discord", "gitlab", "bitbucket", "linkedin", "apple", "x"] as const;
export const standardProviders = ["google", "github", "microsoft", "spotify", "facebook", "discord", "gitlab", "bitbucket", "linkedin", "apple", "x", "twitch"] as const;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding 'twitch' to standardProviders requires a corresponding update to the StandardOAuthProviderType enum in the Prisma schema (schema.prisma). The enum is missing the TWITCH value which will cause type mismatches and potential runtime errors when handling OAuth authentication for Twitch. A database migration will be needed to add this new enum value.


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

Copy link

recurseml bot commented Jun 25, 2025

😱 Found 3 issues. Time to roll up your sleeves! 😱

🗒️ View all ignored comments in this repo
  • The constraint 'TokenStoreType extends string' is too restrictive. It should likely be 'TokenStoreType extends string | object' to match the condition check in line 113 where TokenStoreType is checked against {}
  • Return type mismatch - the interface declares useUsers() returning ServerUser[] but the Team interface that this extends declares useUsers() returning TeamUser[]
  • There is a syntax error in the super constructor call due to the ellipsis operator used incorrectly. Objects aren't being merged correctly. This syntax usage can lead to runtime errors when trying to pass the merged object to 'super()'. Verify that the intended alterations to the object occur before or outside of the super() call if needed.
  • Throwing an error when no active span is found is too aggressive. The log function should gracefully fallback to console.log or another logging mechanism when there's no active span, since not all execution contexts will have an active span. This makes the code less resilient and could break functionality in non-traced environments.

📚 Relevant Docs

  • Function sets backendContext with a new configuration but doesn't pass 'defaultProjectKeys'. Since defaultProjectKeys is required in the type definition and cannot be updated (throws error if tried to set), this will cause a type error.
  • The schema is using array syntax for pick() which is incorrect for Yup schemas. The pick() method in Yup expects individual arguments, not an array. Should be changed to: emailConfigSchema.pick('type', 'host', 'port', 'username', 'sender_name', 'sender_email')

📚 Relevant Docs

  • Creating a refresh token with current timestamp as expiration means it expires immediately. Should set a future date for token expiration.
  • The 'tools' object is initialized as an empty object, even though 'tools' is presumably expected to contain tool definitions. This could cause the server capabilities to lack necessary tool configurations, thus potentially impacting functionalities that depend on certain tool setups.

📚 Relevant Docs

  • 'STACK_SECRET_SERVER_KEY' is potentially being included in every request header without checking its existence again here. Although it's checked during initialization, this could lead to security issues as it's exposed in all communications where the header is logged or captured.

📚 Relevant Docs

  • When adding 'use client' directive at the beginning, it doesn't check if file.text already contains the 'use client' directive. This could lead to duplicate 'use client' directives if the file already has one.

📚 Relevant Docs

Need help? Join our Discord for support!
https://discord.gg/NCpkJ4kF

Copy link

patched-codes bot commented Jun 25, 2025

oauth-button.mdx

  1. Update the provider prop description to include 'twitch' as an example:
    • Current: "The name of the OAuth provider (e.g., 'google', 'github', 'facebook')"
    • Suggested: "The name of the OAuth provider (e.g., 'google', 'github', 'facebook', 'twitch')"

This change is required to reflect the addition of Twitch as a new OAuth provider in the OAuthButton component.

Please ensure these changes are made in the documentation to keep it consistent with the recent updates.

authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
tokenEndpoint: "https://id.twitch.tv/oauth2/token",
tokenEndpointAuthMethod: "client_secret_post",
redirectUri: getEnvVariable("NEXT_PUBLIC_STACK_API_URL") + "/api/v1/auth/oauth/callback/twitch",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a tagged template literal (e.g. urlString``) for constructing the redirect URI, and check response.ok before parsing JSON in fetch to better handle errors.

This comment was generated because it violated a code review rule: mrule_pmzJAgHDlFZgwIwD.

@fomalhautb
Copy link
Contributor

Can you give me permission to edit this PR?

@fomalhautb fomalhautb assigned Nachwahl and unassigned fomalhautb Jul 2, 2025
@Nachwahl
Copy link
Author

Nachwahl commented Jul 4, 2025

Can you give me permission to edit this PR?

Sure! Do you need permission to our respository?

@fomalhautb
Copy link
Contributor

Can you give me permission to edit this PR?

Sure! Do you need permission to our respository?

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

@Nachwahl
Copy link
Author

Nachwahl commented Jul 9, 2025

Can you give me permission to edit this PR?

Sure! Do you need permission to our respository?

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

Done 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants