From c0c534dafb54ebf9f95a5054f576ad99de29f232 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 29 Jun 2021 17:52:00 -0500 Subject: enable strictNullChecks and fix all related issues (#65) --- src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 4f4ad00..647038f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -132,7 +132,12 @@ app.get('/constants', async(req, res) => { app.post('/accounts/createsession', async(req, res) => { try { const { code } = req.body - const { access_token: accessToken, refresh_token: refreshToken } = await discord.exchangeCode(`${mainSiteUrl}/loggedin`, code) + const codeExchange = await discord.exchangeCode(`${mainSiteUrl}/loggedin`, code) + if (!codeExchange) { + res.json({ ok: false, error: 'discord_client_secret isn\'t in env' }) + return + } + const { access_token: accessToken, refresh_token: refreshToken } = codeExchange if (!accessToken) // access token is invalid :( return res.json({ ok: false }) @@ -148,6 +153,8 @@ app.post('/accounts/session', async(req, res) => { try { const { uuid } = req.body const session = await fetchSession(uuid) + if (!session) + return res.json({ ok: false }) const account = await fetchAccountFromDiscord(session.discord_user.id) res.json({ session, account }) } catch (err) { -- cgit