import { AuthUser } from '../../pages/auth/models/AuthUser' ; import { createReducer , on } from '@ngrx/store' ; import { getUserLocal , loginSuccess , logout , registerUserSuccess } from '@store/auth/auth.actions' ; export const authStateKey = 'auth' ; export interface AuthState { user : AuthUser | null ; } export const initialState = { user : null , } ; export const reducer = createReducer < AuthState > ( initialState , on ( loginSuccess , registerUserSuccess , ( state , { user } ) => ( { ... state , user } ) ) , on ( logout , ( ) => initialState ) , on ( getUserLocal , ( state , { user } ) => ( { ... state , user } ) ) ) ; export const getUser = ( state ) => state . user ; export const getToken = ( state ) => state . user ?. token ; export const getUserId = ( state ) => state . user ?. id ?? 0 ; export const isLoggedIn = ( state ) => state . user !== null ;