add twitch oauth login
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
const twitch = require('./twitch')
|
||||
const twitchPublic = require('./twitch-public')
|
||||
const line = require('./line')
|
||||
const google = require('./google')
|
||||
const twitchNew = require('./twitch-new')
|
||||
|
||||
module.exports = {
|
||||
twitch,
|
||||
twitchPublic,
|
||||
line,
|
||||
google
|
||||
google,
|
||||
twitchNew
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const axios = require('axios')
|
||||
const config = require('@config/index')
|
||||
const baseURL = `https://api.twitch.tv/helix`
|
||||
const client = axios.create({
|
||||
baseURL,
|
||||
headers: {
|
||||
'Client-ID': config.twitch.clientid
|
||||
}
|
||||
})
|
||||
|
||||
const tokenHeader = (token) => {
|
||||
if (typeof token !== 'string' || token.trim().length === 0) return null
|
||||
return {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getUserData = async (token = '') => {
|
||||
let headers = tokenHeader(token)
|
||||
if (headers === null) return null
|
||||
let url = '/users'
|
||||
|
||||
let result = await client({
|
||||
method: 'get',
|
||||
headers,
|
||||
url
|
||||
})
|
||||
|
||||
if (!('data' in result) || !('data' in result.data) || !Array.isArray(result.data.data)) return null
|
||||
if (result.data.data.length === 0) return null
|
||||
return result.data.data[0]
|
||||
}
|
||||
@@ -236,7 +236,7 @@ const addTwitch = async (txt = '', source = {}, db) => {
|
||||
return { reply }
|
||||
}
|
||||
|
||||
let twitchUser = await api.twitch.getUserIDByName(name)
|
||||
let twitchUser = await api.twitchPublic.getUserIDByName(name)
|
||||
if (twitchUser === null) return null
|
||||
|
||||
// check channel count
|
||||
|
||||
Reference in New Issue
Block a user