diff --git a/server/models/users.js b/server/models/users.js index e22d83a8..1e6e03a8 100644 --- a/server/models/users.js +++ b/server/models/users.js @@ -160,7 +160,7 @@ module.exports = class User extends Model { // Find existing user let user = await WIKI.models.users.query().findOne({ - providerId: profile.id, + providerId: _.toString(profile.id), providerKey }) @@ -224,7 +224,7 @@ module.exports = class User extends Model { // Create account user = await WIKI.models.users.query().insertAndFetch({ providerKey: providerKey, - providerId: profile.id, + providerId: _.toString(profile.id), email: primaryEmail, name: displayName, pictureUrl: pictureUrl, diff --git a/server/modules/authentication/twitch/authentication.js b/server/modules/authentication/twitch/authentication.js index c9c3a776..e87dfba7 100644 --- a/server/modules/authentication/twitch/authentication.js +++ b/server/modules/authentication/twitch/authentication.js @@ -5,6 +5,7 @@ // ------------------------------------ const TwitchStrategy = require('passport-twitch').Strategy +const _ = require('lodash') module.exports = { init (passport, conf) { @@ -12,14 +13,20 @@ module.exports = { new TwitchStrategy({ clientID: conf.clientId, clientSecret: conf.clientSecret, - callbackURL: conf.callbackURL, - scope: 'user_read' - }, function (accessToken, refreshToken, profile, cb) { - WIKI.models.users.processProfile(profile).then((user) => { - return cb(null, user) || true - }).catch((err) => { - return cb(err, null) || true - }) + callbackURL: conf.callbackURL + }, async (accessToken, refreshToken, profile, cb) => { + try { + const user = await WIKI.models.users.processProfile({ + profile: { + ...profile, + picture: _.get(profile, '_json.logo', '') + }, + providerKey: 'twitch' + }) + cb(null, user) + } catch (err) { + cb(err, null) + } } )) } diff --git a/server/modules/authentication/twitch/definition.yml b/server/modules/authentication/twitch/definition.yml index 0328dee2..02e653ee 100644 --- a/server/modules/authentication/twitch/definition.yml +++ b/server/modules/authentication/twitch/definition.yml @@ -5,8 +5,10 @@ author: requarks.io logo: https://static.requarks.io/logo/twitch.svg color: indigo darken-2 website: https://dev.twitch.tv/docs/authentication/ -isAvailable: false +isAvailable: true useForm: false +scopes: + - user_read props: clientId: type: String