Skip to content

Commit

Permalink
Optimize AJAX auth for guests
Browse files Browse the repository at this point in the history
Only do one check, once. Login will clear the local data anyway.
  • Loading branch information
Tetrakern committed Dec 9, 2024
1 parent f95ee9a commit dae4940
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/application.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js/complete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/utility.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ const FcnGlobals = {

debounceRate: fictioneer_ajax.post_debounce_rate,

/**
* Whether AJAX authentication is enabled.
*
* @type {Boolean}
*/

ajaxAuth: document.documentElement.dataset.fictioneerAjaxAuthValue ?? false,

/**
* Theme fonts.
*
Expand Down Expand Up @@ -235,7 +243,10 @@ application.register('fictioneer', class extends Stimulus.Controller {
}

// Only update from server after some time has passed (e.g. 60 seconds)
if (FcnGlobals.ajaxLimitThreshold < currentUserData.lastLoaded || currentUserData.loggedIn === false) {
if (
(FcnGlobals.ajaxLimitThreshold < currentUserData.lastLoaded || currentUserData.loggedIn === false) &&
currentUserData.loggedIn !== 'pending'
) {
// Prepare event
const event = new CustomEvent(
'fcnUserDataReady',
Expand Down
2 changes: 1 addition & 1 deletion src/js/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const FcnUtils = {
const reset = {
'lastLoaded': data.lastLoaded ?? 0,
'timestamp': 0,
'loggedIn': 'pending',
'loggedIn': (FcnGlobals.ajaxAuth && data.loggedIn === false) ? false : 'pending',
'follows': false,
'reminders': false,
'checkmarks': false,
Expand Down

0 comments on commit dae4940

Please sign in to comment.