I’m building a chatbot that uses Twitch OAuth for authentication. The OAuth flow itself works 100% — I’m getting back the access_token, email, and display_name without issues.
However, when I fetch user info from the Twitch API (https://api.twitch.tv/helix/users), the login field (which should contain the Twitch username) is always null. So even though I can save the other user data and generate the JWT just fine, the login value is missing, and it ends up as null in the JWT payload. Not sure why just this one field isn’t coming through.
I’m using the standard Twitch OAuth2 flow (not OIDC). After a successful login, I exchange the code for an access token, then call https://api.twitch.tv/helix/users using that token to retrieve the user’s Twitch data.
That call returns all expected fields properly, including:
id: 795119794
login: acelightninggaming
display_name: AceLightningGaming
[Admin:ImageRemovedAsContainedNonHiddenEmail]
So the Twitch API is working fine, and login is definitely returned in the response. But when I generate a JWT server-side using jsonwebtoken, login ends up as null inside the JWT payload.
I are not using OIDC or JWTs from Twitch. I generate my own JWT after saving the user to MongoDB. So now I’m just trying to figure out why login is lost in that step. Appreciate any ideas or debugging suggestions!
Then the fault is in your code. Not in the API responses.
jsonwebtoken will take an object passed to it, so the object passed to it is not correctly constructed, but this will be in your code. So we’ll need to debug that
I fetch the Twitch user using the access token from helix.
const twitchUser = userRes.data.data[0];
console.log(“Twitch user fetched:”, twitchUser);
const email = twitchUser.email;
const name = twitchUser.display_name;
const login = twitchUser.login; // ← this is coming in as null
const channelID = twitchUser.id;
2. Just before creating the JWT, I log:
console.log("About to sign JWT with:", {
email,
name,
platforms: {
twitch: {
accessToken: access_token,
login,
channelID,
},
},
});
The console shows login: null, but display_name and email are fine. This suggests the login field is getting lost or not set correctly. But I’ve confirmed the Twitch API is returning a valid login value like acelightninggaming.
Do you spot anything odd or have any suspicions? Is there anything specific you want to look at?