trivia: add session back

This commit is contained in:
Ayden Jahola 2024-09-09 11:48:02 +01:00
parent 4c443fec7c
commit 6c3a6824a9
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -88,7 +88,7 @@ const fetchTriviaQuestion = async (categoryId, categoryName) => {
if (!triviaQuestion || Date.now() - LAST_API_CALL.time >= API_INTERVAL) { if (!triviaQuestion || Date.now() - LAST_API_CALL.time >= API_INTERVAL) {
// If no question was found in the database or API cooldown is over, fetch from API // If no question was found in the database or API cooldown is over, fetch from API
const response = await axios.get( const response = await axios.get(
`https://opentdb.com/api.php?amount=1&category=${categoryId}` `https://opentdb.com/api.php?amount=1&category=${categoryId}&token=${sessionToken}`
); );
const apiQuestion = response.data.results[0]; const apiQuestion = response.data.results[0];
@ -97,7 +97,7 @@ const fetchTriviaQuestion = async (categoryId, categoryName) => {
sessionToken = await resetSessionToken(); // Reset session token sessionToken = await resetSessionToken(); // Reset session token
// Retry fetching the question with the new token // Retry fetching the question with the new token
const retryResponse = await axios.get( const retryResponse = await axios.get(
`https://opentdb.com/api.php?amount=1&category=${categoryId}` `https://opentdb.com/api.php?amount=1&category=${categoryId}&token=${sessionToken}`
); );
const retryApiQuestion = retryResponse.data.results[0]; const retryApiQuestion = retryResponse.data.results[0];
triviaQuestion = await TriviaQuestion.findOne({ triviaQuestion = await TriviaQuestion.findOne({