@@ -37,6 +37,10 @@ import {localStorage} from "../../utils/storage";
3737import handleSession from "../../utils/session" ;
3838import getPlanSelection from "../../utils/get-plan-selection" ;
3939import getPlans from "../../utils/get-plans" ;
40+ import {
41+ storeValue ,
42+ resolveStoredValue ,
43+ } from "../../utils/captive-portal-storage" ;
4044
4145export default class Status extends React . Component {
4246 constructor ( props ) {
@@ -153,13 +157,13 @@ export default class Status extends React.Component {
153157 mustLogout : userMustLogout ,
154158 repeatLogin,
155159 } = userData ;
156- const mustLogin = this . resolveStoredValue (
160+ const mustLogin = resolveStoredValue (
157161 captivePortalSyncAuth ,
158162 `${ orgSlug } _mustLogin` ,
159163 userMustLogin ,
160164 cookies ,
161165 ) ;
162- const mustLogout = this . resolveStoredValue (
166+ const mustLogout = resolveStoredValue (
163167 captivePortalSyncAuth ,
164168 `${ orgSlug } _mustLogout` ,
165169 userMustLogout ,
@@ -227,7 +231,7 @@ export default class Status extends React.Component {
227231 shouldLogin = shouldLogin && settings . payment_requires_internet ;
228232 }
229233 if ( this . loginFormRef && this . loginFormRef . current && shouldLogin ) {
230- this . storeValue (
234+ storeValue (
231235 captivePortalSyncAuth ,
232236 `${ orgSlug } _mustLogin` ,
233237 false ,
@@ -494,7 +498,7 @@ export default class Status extends React.Component {
494498 // After a successful payment, the user is redirected back to the status page.
495499 // If the user plan was previously exhausted, they need to be logged into the captive portal
496500 // to regain internet access. This ensures seamless browsing after upgrading their plan.
497- this . storeValue (
501+ storeValue (
498502 captivePortalSyncAuth ,
499503 `${ orgSlug } _mustLogin` ,
500504 true ,
@@ -582,7 +586,7 @@ export default class Status extends React.Component {
582586 this . repeatLogin = true ;
583587 }
584588 if ( ! internetMode ) {
585- this . storeValue (
589+ storeValue (
586590 captivePortalSyncAuth ,
587591 `${ orgSlug } _mustLogout` ,
588592 true ,
@@ -699,7 +703,7 @@ export default class Status extends React.Component {
699703 const userAutoLogin = localStorage . getItem ( "userAutoLogin" ) === "true" ;
700704 if (
701705 loggedOut ||
702- this . resolveStoredValue (
706+ resolveStoredValue (
703707 captivePortalSyncAuth ,
704708 `${ orgSlug } _mustLogout` ,
705709 false ,
@@ -811,60 +815,6 @@ export default class Status extends React.Component {
811815 }
812816 } ;
813817
814- // eslint-disable-next-line class-methods-use-this
815- storeValue = ( captivePortalSyncAuth , key , value , cookies ) => {
816- /**
817- * Stores a value in both cookies and localStorage if synchronous
818- * captive portal authentication is enabled.
819- *
820- * In synchronous authentication, submitting the captive portal form
821- * triggers a page reload, which resets the component state.
822- * Storing the value in cookies ensures it persists across reloads.
823- *
824- * The value is also saved in localStorage as a fallback in case the browser does not support cookies.
825- *
826- * @param {boolean } captivePortalSyncAuth - Whether synchronous authentication is enabled.
827- * @param {string } key - The key under which the value is stored.
828- * @param {boolean } value - The value to store.
829- * @param {Cookies } cookies - The cookies instance used to set the cookie.
830- */
831- if ( ! captivePortalSyncAuth ) {
832- return ;
833- }
834- localStorage . setItem ( key , value ) ;
835- cookies . set ( key , value , { path : "/" , maxAge : 60 } ) ;
836- } ;
837-
838- // eslint-disable-next-line class-methods-use-this
839- resolveStoredValue = ( captivePortalSyncAuth , key , fallback , cookies ) => {
840- /**
841- * Resolves the correct value by checking cookies, then localStorage,
842- * falling back to a default value if neither is found.
843- *
844- * @param {boolean } captivePortalSyncAuth - Whether synchronization is enabled.
845- * @param {string } cookieKey - The key to look for in cookies and localStorage.
846- * @param {* } fallback - The fallback value if no valid stored value is found.
847- * @returns {* } - The selected value based on storage or fallback.
848- */
849- if ( ! captivePortalSyncAuth ) {
850- return fallback ;
851- }
852-
853- const cookieValue = cookies . get ( key ) ;
854- if ( cookieValue !== undefined ) {
855- localStorage . removeItem ( key ) ;
856- return cookieValue ;
857- }
858-
859- const localStorageValue = localStorage . getItem ( key ) ;
860- if ( localStorageValue !== null ) {
861- localStorage . removeItem ( key ) ;
862- return localStorageValue === "true" ;
863- }
864-
865- return fallback ;
866- } ;
867-
868818 updateScreenWidth = ( ) => {
869819 this . setStateSafe ( { screenWidth : window . innerWidth } ) ;
870820 } ;
0 commit comments