0

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?

The Amateur Coder
  • 789
  • 3
  • 11
  • 33
J4N
  • 19,480
  • 39
  • 187
  • 340
  • I've created a reproducible here and it works fine for me: https://stackblitz.com/edit/ngxs-selector-issue-so-64232855?file=src%2Fapp%2Fapp.state.ts Could you check it out and see what are the possible differences between it and your code so we can pin down the issue? – Mateus Carniatto Nov 18 '20 at 19:26
  • Honestly I don't have access to this code anymore and I'm unable to reproduce it now, sorry. – J4N Nov 19 '20 at 05:57

0 Answers0