diff --git a/src/app.ts b/src/app.ts index 9544820..0c75db8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -258,7 +258,7 @@ app.get("/callback", async (request, response) => { 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.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]); if (typeof streamer == 'undefined' || request.session.user.id == streamer['userid']) { 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); 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)); - 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) { response.render('main.eta', { loggedIn: false,