/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 */

import {Actions} from './';

export const USER_UNAUTHORIZED = 'Unauthorized.';
export const USER_NOT_SIGNEDIN = 'Not signed in.';

export type User = {
  name?: string;
  profile_picture?: {
    uri: string;
  };
};

export type State = User;

export type Action =
  | {
      type: 'LOGIN';
      payload: User;
    }
  | {
      type: 'LOGOUT';
    };

const INITIAL_STATE: State = {};

export default function reducer(
  state: State = INITIAL_STATE,
  action: Actions,
): State {
  if (action.type === 'LOGOUT') {
    return {};
  } else if (action.type === 'LOGIN') {
    return {
      ...state,
      ...action.payload,
    };
  } else {
    return state;
  }
}

export const login = (payload: User): Action => ({
  type: 'LOGIN',
  payload,
});

export const logout = (): Action => ({
  type: 'LOGOUT',
});

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 */

import {Actions} from './';

export const USER_UNAUTHORIZED = 'Unauthorized.';
export const USER_NOT_SIGNEDIN = 'Not signed in.';

export type User = {
  id?: string;
  name?: string;
  profile_picture?: {
    uri: string;
  };
};

export type State = User;

export type Action =
  | {
      type: 'LOGIN';
      payload: User;
    }
  | {
      type: 'LOGOUT';
    };

const INITIAL_STATE: State = {};

export default function reducer(
  state: State = INITIAL_STATE,
  action: Actions,
): State {
  if (action.type === 'LOGOUT') {
    return {};
  } else if (action.type === 'LOGIN') {
    return {
      ...state,
      ...action.payload,
    };
  } else {
    return state;
  }
}

export const login = (payload: User): Action => ({
  type: 'LOGIN',
  payload,
});

export const logout = (): Action => ({
  type: 'LOGOUT',
});

Include ID for logged-in User
Include ID for logged-in User

Summary: Adding id field for the currently logged in user in the store's state

Reviewed By: passy

Differential Revision: D20928642

fbshipit-source-id: eff5373bd88ed8fd228193b47649f586cf20b585
