diff --git a/server/src/action-utils.js b/server/src/action-utils.js
index bac03da6..95464844 100644
--- a/server/src/action-utils.js
+++ b/server/src/action-utils.js
@@ -74,8 +74,8 @@ async function createRecord(Cache, tableName, records) {
newRecords.forEach(record => {
Cache.set(cleanID(record.id), deAirtable(record.fields), { eager: true });
});
- console.log(newRecords.length);
- console.log(newRecords);
+ // console.log(newRecords.length);
+ // console.log(newRecords);
} catch (e) {
console.error("Airtable create failed", e);
return { error: true, errorMessage: e.message };
diff --git a/server/src/routes.js b/server/src/routes.js
index 710f17a4..1623514e 100644
--- a/server/src/routes.js
+++ b/server/src/routes.js
@@ -308,7 +308,7 @@ module.exports = ({ app, cors, Cache, io }) => {
if (!TwitchEnvSet) return res.status(503).send({ error: true, message: "Twitch authentication is disabled on the server." });
let state = createState();
states[state] = req.params.scopes;
- res.redirect(`https://id.twitch.tv/oauth2/authorize?client_id=${process.env.TWITCH_CLIENT_ID}&redirect_uri=${process.env.TWITCH_REDIRECT_URI}&response_type=code&scope=${req.params.scopes}&force_verify=true`);
+ res.redirect(`https://id.twitch.tv/oauth2/authorize?client_id=${process.env.TWITCH_CLIENT_ID}&redirect_uri=${process.env.TWITCH_REDIRECT_URI}&response_type=code&scope=${req.params.scopes}&force_verify=true&state=${state}`);
});
@@ -332,14 +332,15 @@ module.exports = ({ app, cors, Cache, io }) => {
if (existingChannel) {
airtableResponse = await updateRecord(Cache, "Channels", existingChannel.id, {
"Twitch Refresh Token": tokenInfo.accessToken,
- "Twitch Scopes": tokenInfo.scopes.join(" "),
+ "Twitch Scopes": tokenInfo.scope.join(" "),
"Channel ID": tokenInfo.userId,
"Name": tokenInfo.userName
});
+
} else {
airtableResponse = await createRecord(Cache, "Channels", [{
"Twitch Refresh Token": tokenInfo.accessToken,
- "Twitch Scopes": tokenInfo.scopes.join(" "),
+ "Twitch Scopes": tokenInfo.scope.join(" "),
"Channel ID": tokenInfo.userId,
"Name": tokenInfo.userName
}]);
@@ -347,10 +348,13 @@ module.exports = ({ app, cors, Cache, io }) => {
// console.log(airtableResponse);
- return res.send("okay thanks");
+ if (airtableResponse.error) {
+ return res.status(400).send({ error: true, errorMessage: airtableResponse.errorMessage });
+ }
+ return res.send("poggers thanks");
} catch (e) {
console.error("[Twitch Auth] error", e);
- res.status(400).send({ error: true, errorMessage: e.message});
+ res.status(400).send({ error: true, errorMessage: e.message });
}
});
diff --git a/website/src/components/website/TwitchAuthScopeSelector.vue b/website/src/components/website/TwitchAuthScopeSelector.vue
new file mode 100644
index 00000000..5344939d
--- /dev/null
+++ b/website/src/components/website/TwitchAuthScopeSelector.vue
@@ -0,0 +1,50 @@
+
+
+
Give our systems access to a twitch account
+
+
+
+
+
Authorize
+
+
+
+
+
diff --git a/website/src/router/default.js b/website/src/router/default.js
index bded175b..30d0b820 100644
--- a/website/src/router/default.js
+++ b/website/src/router/default.js
@@ -12,6 +12,7 @@ import SharedRoutes from "@/router/shared-routes";
import Authenticator from "@/views/Authenticator";
import Dashboard from "@/views/Dashboard";
import ProfilePage from "@/views/ProfilePage";
+import TwitchAuthScopeSelector from "@/components/website/TwitchAuthScopeSelector";
export default [
{
@@ -59,6 +60,10 @@ export default [
path: "/auth/discord/return",
props: route => ({ code: route.query.code }),
component: Authenticator
+ },
+ {
+ path: "/twitch-auth",
+ component: TwitchAuthScopeSelector
}
]
},