text: import Vue from 'vue';
  import Vuex from 'vuex';
  
  Vue.use( Vuex );
  
  const Utils = require( '../Utils' );
  
  export default new Vuex.Store( {
  	state: {
  		/**
  		 * @property { string } id
  		 * @property { string } discriminator
  		 * @property { string } email
  		 * @property { number } flags
  		 * @property { string } locale
  		 * @property { boolean } mfa_enabled
  		 * @property { number } premium_type
  		 * @property { number } public_flags
  		 * @property { string } username
  		 * @property { boolean } verified
  		 * @property { string } token
  		 */
  		user: JSON.parse( localStorage.getItem( 'user' ) )
  	},
  	mutations: {
  		auth_request( state ) {
  			state.status = 'loading';
  		},
  		auth_success( state, user ) {
  			state.status = 'success';
  			state.user = user;
  		},
  		auth_error( state ) {
  			state.status = 'error';
  		},
  		token( state, token ) {
  			state.user.token = token;
  		},
  		logout( state ) {
  			state.user = undefined;
  			localStorage.removeItem( 'user' );
  		}
  	},
  	actions: {
  		async auth( { commit }, token ) {
  			if ( this.user ) { return commit( 'auth_error' ); }
  			commit( 'auth_request' );
  			try {
  				const res = await fetch( '/api/auth/authorize', { headers: { Authorization: `Token ${token}` }, method: 'get' } );
  				if ( !res.ok ) { return commit( 'auth_error' ); }
  				const data = await res.json();
  				data.token = token;
  				commit( 'auth_success', data );
  				localStorage.setItem( 'user', JSON.stringify( data ) );
  			} catch ( e ) {
  				commit( 'auth_error' );
  			}
  		},
  		logout( { commit } ) {
  			localStorage.removeItem( 'user' );
  			commit( 'logout' );
  		}
  	},
  	modules: {},
  	getters: {
  		currentUser: ( state ) => state.user,
  		avatar: ( state ) => state.user ?
  			Utils.getAvatar( state.user ) :
  			'',
  		user: ( state ) => ( id ) => id === state.user.id ? state.user : state.users.find( ( u ) => u.id === id )
  	}
  } );
  