import { makeAutoObservable , observable , action } from "mobx" ; import * as Storage from './localStorage' ; import { initAxios , axios } from '../api' ; class UserStore { @ observable me : any ; constructor ( ) { const user = Storage . getItem ( 'me' ) ; user ?. then ( ( u ) => { this . setMe ( u ) ; } ) ; makeAutoObservable ( this ) ; } @ action . bound login ( user ) { this . setMe ( user ) ; Storage . setItem ( 'me' , this . me ) ; } @ action . bound loginOut ( ) { this . me = undefined ; Storage . removeItem ( 'me' ) ; } @ action . bound setMe ( user ) { this . me = user ; initAxios ( ) ; Storage . setItem ( 'me' , this . me ) ; } @ action . bound updateInfo ( ) { axios . get ( '/member/user/info' ) . then ( ( res ) => { const { success , data } = res ?. data ; if ( success && data ) { this . setMe ( { ... this . me , loggedInUser : { ... data } } ) ; } } ) ; } } export default new UserStore ( ) ;