@@ -35,18 +35,16 @@ export function makeAppStateService() {
3535 @options ( persist ( window . localStorage ) )
3636 userPreferences : UserPreferences | null = null ;
3737
38- // TODO persist here
38+ // TODO persist here instead of in AuthService
3939 auth : Auth | null = null ;
4040
41+ // Store logged-in flag in local storage so that tabs know whether to
42+ // check auth again when focused
43+ @options ( persist ( window . localStorage ) )
44+ loggedIn : boolean | null = null ;
45+
4146 // Store user's org slug preference in local storage in order to redirect
4247 // to the most recently visited org on next log in.
43- //
44- // FIXME Since the org slug preference is removed on log out, AuthService
45- // currently checks whether `orgSlug` is being removed in a `storage`
46- // event to determine whether another tab has logged out.
47- // It's not the cleanest solution to use `orgSlug` as a cross-tab logout
48- // event, so we may want to refactor this in the future.
49- //
5048 // TODO move to `userPreferences`
5149 @options ( persist ( window . localStorage ) )
5250 orgSlug : string | null = null ;
@@ -103,11 +101,13 @@ export function makeAppStateService() {
103101 appState . settings = settings ;
104102 }
105103
104+ @transaction ( )
106105 @unlock ( )
107106 updateAuth ( authState : AppState [ "auth" ] ) {
108107 authSchema . nullable ( ) . parse ( authState ) ;
109108
110109 appState . auth = authState ;
110+ appState . loggedIn = Boolean ( authState ) ;
111111 }
112112
113113 @transaction ( )
@@ -188,6 +188,7 @@ export function makeAppStateService() {
188188
189189 private _resetUser ( ) {
190190 appState . auth = null ;
191+ appState . loggedIn = null ;
191192 appState . userInfo = null ;
192193 appState . userPreferences = null ;
193194 appState . orgSlug = null ;
0 commit comments