Twitch Login with Authentication

Used Twitch Authentication
OAuth Redirect URLs on Twitch Developer Console: Sign-in Complete
Set the useProxy as true. But after Authorizing in Twitch, the next screen shows up as follows

WebBrowser.maybeCompleteAuthSession();

// Endpoint
const discovery = {
  authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
  tokenEndpoint: "https://id.twitch.tv/oauth2/token",
  revocationEndpoint: "https://id.twitch.tv/oauth2/revoke",
};

const Twitch = () => {
  const [request, response, promptAsync] = useAuthRequest(
    {
      clientId: TWITCH_CLIENT_ID,
      redirectUri: makeRedirectUri({
        useProxy: true,
        //   scheme:"your.app"
      }),
      scopes: ["openid", "user_read"],
    },
    discovery
  );

  React.useEffect(() => {
    if (response?.type === "success") {
      const { code } = response.params;
      console.log(response);
    }
  }, [response]);

  return (
    <Button
      disabled={!request}
      title="Twitch Login"
      onPress={() => {
        promptAsync();
      }}
    />
  );
};

Works with AuthSession.startAsync with the same variables as in useAuthRequest.

const getTwitchUserInformation = (twitchToken) => {
  console.log(twitchToken);
};

const signInWithTwitch = async () => {
  const redirectUrl = AuthSession.makeRedirectUri({ useProxy: true });
  const authUrl = `https://id.twitch.tv/oauth2/authorize?client_id=${TWITCH_CLIENT_ID}&redirect_uri=${redirectUrl}&response_type=token&scope=openid+user_read&force_verify=true`;
  const { type, params } = await AuthSession.startAsync({ authUrl });
  if (type === "success") {
    const { access_token, token_type } = params;
    getTwitchUserInformation(access_token);
  }
};

const Twitch = () => {
  return (
    <Button
      title="Twitch Auth Login"
      onPress={() => {
        signInWithTwitch();
      }}
    />
  );
};

The above code works oke. Not sure what the issue is with the one in previous reply. Any help is appreciated. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.