1 import { IActionHandler } from '../flux/action';
2 import { UpdateAuthentication } from '../actions/authentication';
4 import { User } from '../models/authentication';
6 export interface IAuthenticationState {
10 const initialToken = localStorage.getItem("userToken");
12 const authenticationStateInit: IAuthenticationState = {
13 user: initialToken && User.fromString(initialToken) || undefined
16 export const authenticationStateHandler: IActionHandler<IAuthenticationState> = (state = authenticationStateInit, action) => {
17 if (action instanceof UpdateAuthentication) {
19 const user = action.bearerToken && new User(action.bearerToken) || undefined;
21 localStorage.setItem("userToken", user.toString());
23 localStorage.removeItem("userToken");