Skip to content

Commit 87485e1

Browse files
authored
Merge pull request #302 from KenEucker/develop
Trying to resolve the 400 errors.
2 parents bcb4d86 + 6e88de3 commit 87485e1

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

functions/common/methods.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import nodemailer from 'nodemailer'
1414
import { extname, join } from 'path'
1515
import qs from 'qs'
1616
import {
17+
BikeTagEnv,
1718
getDomainInfo,
1819
getImageSized,
1920
getTagDateISOFromTimezone,
@@ -498,7 +499,10 @@ export const getPayloadAuthorization = async (
498499
const { payload } = await jose.jwtVerify(authStr, JWKS)
499500
return payload
500501
} catch (e: any) {
501-
if (e.code === 'ERR_JWT_EXPIRED') return null
502+
if (e.code === 'ERR_JWT_EXPIRED') {
503+
log('Auth0 JWT expired', e, 'warn')
504+
return null
505+
}
502506
log('Auth0 JWT verification error', e, 'warn')
503507
return authStr
504508
}
@@ -857,9 +861,14 @@ export const archiveAndClearQueue = async (
857861
{ game: queuedTags[0].game },
858862
{ source: 'sanity' },
859863
)
860-
game = gameResponse.success ? gameResponse.data : undefined
864+
if (gameResponse.success) {
865+
game = gameResponse.data
866+
} else {
867+
return { results: [{ message: ErrorMessage.GameNotSet, game: undefined }], errors: true }
868+
}
861869
}
862-
const imageSource = game?.awsRegion ? 'aws' : 'imgur'
870+
871+
const imageSource = getImageSource(game)
863872

864873
if (queuedTags.length && game) {
865874
const nonAdminBikeTagOpts = getBikeTagClientOpts(undefined, true, false, game)
@@ -1939,5 +1948,5 @@ export const getImageSource = (game: Game): 'aws' | 'imgur' => {
19391948
} else if (game.mainhash?.length) {
19401949
return 'imgur'
19411950
}
1942-
return 'imgur'
1951+
return BikeTagEnv.IMAGE_SOURCE as 'aws' | 'imgur'
19431952
}

src/common/constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const BikeTagDefaults = {
66
hostKey: 'ItsABikeTagGame',
77
logo: '/images/BikeTag.svg',
88
jingle: 'media/biketag-jingle-1.mp3',
9-
imageSource: 'imgur',
9+
imageSource: 'aws',
1010
gameSource: 'sanity',
1111
store: 'biketag',
1212
cacheResetInterval: '5000',
@@ -41,11 +41,10 @@ export const BikeTagEnv = {
4141
B_KEY: process.env.B_KEY ?? process.env.CLIENT_KEY ?? null,
4242
/* BikeTag Configuration */
4343
GAME_NAME: process.env.GAME_NAME ?? null,
44-
GAME_SOURCE: process.env.GAME_SOURCE ?? BikeTagDefaults.gameSource ?? null,
45-
IMAGE_SOURCE: process.env.IMAGE_SOURCE ?? BikeTagDefaults.imageSource ?? null,
44+
GAME_SOURCE: process.env.GAME_SOURCE ?? BikeTagDefaults.gameSource,
45+
IMAGE_SOURCE: process.env.IMAGE_SOURCE ?? BikeTagDefaults.imageSource,
4646
HOST: process.env.HOST ?? BikeTagDefaults.host ?? null,
4747
BIKETAG_AUTHED: process.env.BIKETAG_AUTHED ?? null,
48-
DEFAULT_IMAGE_SOURCE: process.env.DEFAULT_IMAGE_SOURCE ?? BikeTagDefaults.imageSource ?? 'imgur',
4948
/* Google Configuration */
5049
G_AKEY:
5150
process.env.G_AKEY ?? process.env.GOOGLE_ACCESS_TOKEN ?? process.env.GOOGLE_API_KEY ?? null,

src/store/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, {
172172
},
173173
})
174174
.catch((e) => {
175+
/// THIS IS COSTLY
176+
this.auth0Token = undefined
177+
localStorage.clear()
178+
this.SET_PROFILE()
175179
console.error('error fetching profile', e)
176180
return e
177181
})
@@ -243,7 +247,7 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, {
243247
}
244248
},
245249
async fetchCredentials(fetchNewCredentials = false) {
246-
if (!this.credentialsFetched || fetchNewCredentials) {
250+
if ((!this.credentialsFetched && !this.token?.length) || fetchNewCredentials) {
247251
try {
248252
const biketagConf = await client.fetchCredentials(`player-id ${this.profile.sub}`)
249253
if (biketagConf?.biketag?.clientToken) {
@@ -745,7 +749,7 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, {
745749
// ======= mutations ================================================
746750
// ==================================================================
747751

748-
SET_PROFILE(profile: any) {
752+
SET_PROFILE(profile?: any) {
749753
const oldState = this.profile
750754

751755
if (

0 commit comments

Comments
 (0)