Added GET /api/auth/twitch/users route.
This commit is contained in:
28
src/index.ts
28
src/index.ts
@ -238,7 +238,7 @@ app.get('/api/twitch/redemptions', apiMiddlewares, async (req: any, res: any, ne
|
||||
const rest = new httpm.HttpClient(null);
|
||||
const resp = await rest.get('https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=' + account.providerAccountId, {
|
||||
'Authorization': 'Bearer ' + connection.accessToken,
|
||||
'Client-Id': connection.clientId
|
||||
'Client-Id': connection.clientId,
|
||||
});
|
||||
|
||||
const twitch = JSON.parse(await resp.readBody());
|
||||
@ -251,6 +251,32 @@ app.get('/api/twitch/redemptions', apiMiddlewares, async (req: any, res: any, ne
|
||||
res.send(twitch.data);
|
||||
});
|
||||
|
||||
app.get("/api/auth/twitch/users", apiMiddlewares, async (req: any, res: any) => {
|
||||
const username = req.query.login.toLowerCase();
|
||||
if (!username) {
|
||||
res.send({ user: null });
|
||||
return;
|
||||
}
|
||||
|
||||
const rest = new httpm.HttpClient(null);
|
||||
const userId = req.user.impersonation?.id ?? req.user.id;
|
||||
|
||||
const connection: any = await db.oneOrNone('SELECT "clientId", "accessToken" FROM "Connection" WHERE "userId" = $1 AND "default" = true AND "type" = \'twitch\'', userId);
|
||||
|
||||
const resp = await rest.get('https://api.twitch.tv/helix/users?login=' + username, {
|
||||
'Authorization': 'Bearer ' + connection.accessToken,
|
||||
'Client-Id': connection.clientId,
|
||||
});
|
||||
const twitch = JSON.parse(await resp.readBody());
|
||||
if (!twitch?.data) {
|
||||
res.send({ user: null });
|
||||
return;
|
||||
}
|
||||
|
||||
const user = twitch.data.find((u: any) => u.login == username);
|
||||
res.send({ user });
|
||||
});
|
||||
|
||||
app.post("/api/auth/twitch/callback", async (req: any, res: any) => {
|
||||
const query = `client_id=${process.env.AUTH_CLIENT_ID}&client_secret=${process.env.AUTH_CLIENT_SECRET}&code=${req.body.code}&grant_type=authorization_code&redirect_uri=${process.env.AUTH_REDIRECT_URI}`
|
||||
const rest = new httpm.HttpClient(null);
|
||||
|
Reference in New Issue
Block a user