Wait for updateUser to complete before updating streamer
Fixes unhandled promise rejection when setting up new instancemaster
parent
ee5d14b5f5
commit
39098f2346
|
@ -258,7 +258,7 @@ app.get("/callback", async (request, response) => {
|
||||||
if (typeof tokenResponse == 'undefined') throw new Error('tokenResponse is undefined');
|
if (typeof tokenResponse == 'undefined') throw new Error('tokenResponse is undefined');
|
||||||
request.session.tokenpair = { access_token: tokenResponse.access_token, refresh_token: tokenResponse.refresh_token };
|
request.session.tokenpair = { access_token: tokenResponse.access_token, refresh_token: tokenResponse.refresh_token };
|
||||||
request.session.user = (await twitch.apiRequest(request.session.tokenpair,"/users")).data[0];
|
request.session.user = (await twitch.apiRequest(request.session.tokenpair,"/users")).data[0];
|
||||||
db.query(Object.assign(queries.updateUser,{ values: [request.session.user.id,request.session.user.display_name,request.session.user.profile_image_url] }));
|
await db.query(Object.assign(queries.updateUser,{ values: [request.session.user.id,request.session.user.display_name,request.session.user.profile_image_url] }));
|
||||||
var streamer = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]);
|
var streamer = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]);
|
||||||
if (typeof streamer == 'undefined' || request.session.user.id == streamer['userid']) {
|
if (typeof streamer == 'undefined' || request.session.user.id == streamer['userid']) {
|
||||||
if (typeof (tokenResponse as any).scope != 'undefined') { // Scopes requested - update streamer info
|
if (typeof (tokenResponse as any).scope != 'undefined') { // Scopes requested - update streamer info
|
||||||
|
@ -276,7 +276,10 @@ app.get("/", async (request, response) => {
|
||||||
if (request.session) await validateApiToken(request.session);
|
if (request.session) await validateApiToken(request.session);
|
||||||
var streamerInfo = await db.query(queries.getStreamerInfo).then((result: pg.QueryResult) => result.rows[0]);
|
var streamerInfo = await db.query(queries.getStreamerInfo).then((result: pg.QueryResult) => result.rows[0]);
|
||||||
var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state));
|
var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state));
|
||||||
if (typeof streamerInfo == 'undefined') response.redirect(307, `https://id.twitch.tv/oauth2/authorize?client_id=${config.twitchClientId}&redirect_uri=${config.urlPrefix}/callback&response_type=code&scope=channel:read:subscriptions moderation:read`);
|
if (typeof streamerInfo == 'undefined') {
|
||||||
|
response.redirect(307, `https://id.twitch.tv/oauth2/authorize?client_id=${config.twitchClientId}&redirect_uri=${config.urlPrefix}/callback&response_type=code&scope=channel:read:subscriptions moderation:read`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!request.session || !request.session.user) {
|
if (!request.session || !request.session.user) {
|
||||||
response.render('main.eta', {
|
response.render('main.eta', {
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
|
|
Loading…
Reference in New Issue