Fix: check summoner name server side to prevent Firefox error

This commit is contained in:
Valentin Kaelin 2019-09-03 19:56:41 +02:00
parent afd1b0d8f3
commit 1c1dc49c69
4 changed files with 23 additions and 16 deletions

View file

@ -7,7 +7,7 @@
type="text"
autofocus
class="input w-full px-2 py-4 rounded-lg outline-none pl-8 pr-16 font-bold"
>
/>
<div class="absolute right-0 z-30 vertical-center flex items-center h-full mr-2">
<div
@click="dropdown = !dropdown"
@ -42,8 +42,7 @@
name="check"
scale="0.7"
class="absolute vertical-center offsetIcon"
>
</v-icon>
></v-icon>
{{ region }}
</div>
</div>
@ -86,15 +85,9 @@ export default {
}
},
formSubmit() {
const regexNames = new RegExp('^[0-9\\p{L} _\\.]+$', 'u')
if(regexNames.exec(this.summoner)) {
this.$emit('formSubmit', this.summoner.split(' ').join(''), this.selectedRegion.toLowerCase())
} else {
this.$store.dispatch('notification/add', {
type: 'error',
message: 'Summoner Name entered is incorrect.'
})
const search = this.summoner.split(' ').join('')
if (search.length) {
this.$emit('formSubmit', search, this.selectedRegion.toLowerCase())
}
}
}

View file

@ -140,6 +140,11 @@ export default {
} else {
this.summonerFound = false
this.loading = false
this.$store.dispatch('notification/add', {
type: 'error',
message: 'Summoner not found.'
})
console.log('Summoner not found')
}
} catch (error) {

View file

@ -16,7 +16,7 @@ class JaxRequest {
return JSON.parse(resp)
} catch ({ statusCode, ...rest }) {
console.log('error: ' + statusCode, rest)
console.log('error: ' + statusCode)
}
}

View file

@ -42,11 +42,21 @@ app.post('/api', async function (req, res) {
console.log(req.body.summoner, req.body.region)
console.time('all')
/* Check if the summonerName is correct before fetching Riot API */
const regexSummonerName = new RegExp('^[0-9\\p{L} _\\.]+$', 'u')
if (!regexSummonerName.exec(req.body.summoner)) {
return res.send(null)
}
const finalJSON = {}
jax.regionName = req.body.region
try {
const account = await jax.Summoner.summonerName(req.body.summoner)
// Check if the summoner is found
if (!account) return res.send(null)
finalJSON.account = account
const ranked = await jax.League.summonerID(account.id)
@ -66,7 +76,6 @@ app.post('/api', async function (req, res) {
console.timeEnd('all')
} catch (error) {
console.log('username not found')
console.log(error)
res.send(null)
}
})