1.0.8 • Published 3 years ago

company-auth-app v1.0.8

Weekly downloads
150
License
-
Repository
-
Last release
3 years ago

Como adicionar esta lib ao seu projeto

passo 1 - Instalação

Se você usa yarn

$ yarn add company-auth-app

Se você usa npm

$ npm i company-auth-app

passo 2 - Adicionar o stack de navegação na root

Se você criou o seu projeto com o nosso CLI, execute os seguintes passos

Adicionar como TAB na root

  • Abra o arquivo App.tsx (arquivo se encontra no root do projeto) e adicione o seguinte código:

    $ return (
      <AppRoot store={store} theme={theme} themeMode="light">
        <AuthSwitchStackNavigator
          theme={theme}
          themeMode="light"
          initialRouteName="SEU_INITIAL_ROUTE_NAME">
          <BottomTab.Screen
            name="SEU_ROOT_NAVIGATOR_TAB_NAME"
            component={SEU_ROOT_NAVIGATOR}
            options={{
              tabBarIcon: ({color}) => (
                <TabBarIcon name="..." color={color} />
              ),
            }}
          />
        </AuthSwitchStackNavigator>
      </AppRoot>
    );

passo 3 - Adicionar o store

  • Abra o arquivo src/store/epics.tsx e adicione o seguinte código:
    $ export const rootEpic = combineEpics(
    [...]
    authEpics,
    [...]
    );
  • Abra o arquivo src/store/index.tsx e adicione o seguinte código:

    $ const rootReducer = combineReducers({
    [...]
    auth: authSlice.reducer,
    [...]
    });

API

Obter o usuário logado (Class Components)

 const mapStateToProps = (state: AuthState) => {
  const user = authSelectUser(state);
  return {user};
}; 

Fazer logout (Class Components)

const mapStateToDispatch = (disptach: any) => {
  return {logout: () => disptach(authLogout())};
};

Pronto.