Why my selector function in NGXS receives null when the state has been populated?

440 views Asked by At

I have an Ionic app with NGXS that I'm trying to setup. I'm doing the Auth part.

So far I've this model:

export interface AuthStateModel {
  profile: Profile | null;
  loaded: boolean;
}

and this AuthState:

@State<AuthStateModel>({
  name: 'auth',
  defaults: {
    profile: null,
    loaded: false,
  },
})
@Injectable()
export class AuthState {

  @Selector()
  static profile(state: AuthStateModel) {
    return state.profile;
  }
  @Selector()
  static isLoggedIn(state: AuthStateModel) {
    console.log(state);<--- loggin the state value
    return state.loaded;
  }
  constructor(private angularFireAuth: AngularFireAuth, private angularFireStore: AngularFirestore) {}


  //... Some actions
}

In my app component, I'm doing this to retrieve my state value:

@Select(AuthState.isLoggedIn) isLoggedIn$: Observable<boolean>;

But I really don't understand, it appears that the state is set, but my selector still receives null: enter image description here

What did I mess up?

0

There are 0 answers