1.1.48 • Published 2 months ago

@os-team/auth-mobile v1.1.48

Weekly downloads
-
License
UNLICENSED
Repository
gitlab
Last release
2 months ago

@os-team/auth-mobile NPM version BundlePhobia

The authentication module for os-team's mobile apps.

Installation

Install the package using the following command:

yarn add @os-team/auth-mobile

Install peer dependencies:

npx install-peerdeps @os-team/auth-mobile

Install pods:

npx pod-install

Add to the ios/MyProject/Info.plist file the following key:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>message</string>
    <string>readdle-spark</string>
    <string>airmail</string>
    <string>ms-outlook</string>
    <string>googlegmail</string>
    <string>inbox-gmail</string>
    <string>ymail</string>
    <string>superhuman</string>
    <string>yandexmail</string>
</array>

Add to the android/app/src/main/AndroidManifest.xml file inside the manifest tag the following content:

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="mailto"/>
  </intent>
</queries>

Replace the NavigationContainer from the @react-navigation/native package with the AuthNavigationContainer from the @os-team/auth-mobile package as follows:

import 'react-native-gesture-handler';
import React from 'react';
import { useColorScheme } from 'react-native';
import { RelayEnvironmentProvider } from 'react-relay/hooks';
import { ThemeProvider } from '@os-design-mobile/theming';
import createRelayEnvironment from './utils/createRelayEnvironment';
import AuthenticatedNavigator, {
  authenticatedInitialRouteName,
  authenticatedScreens,
} from './screens/AuthenticatedNavigator';
import { AuthNavigationContainer } from '@os-team/auth-mobile';

require('./i18next');

const PREFIXES = ['englika://', 'https://englika.com', 'https://englika.ru'];

const relayEnvironment = createRelayEnvironment();

const App: React.FC = () => {
  const colorScheme = useColorScheme();

  return (
    <RelayEnvironmentProvider environment={relayEnvironment}>
      <ThemeProvider initialTheme={colorScheme || undefined}>
        <AuthNavigationContainer
          secondLevelDomain='englika'
          linking={{
            prefixes: PREFIXES,
            config: {
              initialRouteName: authenticatedInitialRouteName,
              screens: authenticatedScreens,
            },
          }}
        >
          <AuthenticatedNavigator />
        </AuthNavigationContainer>
      </ThemeProvider>
    </RelayEnvironmentProvider>
  );
};

export default App;

Add locales in the i18next options:

import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import RNLanguageDetector from '@os-team/i18next-react-native-language-detector';
import { locales } from '@os-team/auth-mobile';

i18next
  .use(RNLanguageDetector)
  .use(initReactI18next)
  .init({
    fallbackLng: 'en',
    supportedLngs: ['en', 'ru'],
    ns: [],
    defaultNS: undefined,

    resources: {
      en: {
        auth: locales.en, // Add this line
      },
      ru: {
        auth: locales.ru, // Add this line
      },
    },

    interpolation: {
      escapeValue: false,
    },
  });

export default i18next;

Add the token middleware:

import { Environment, RecordSource, Store } from 'relay-runtime';
import createRelayNetwork from '@os-team/relay-network-creator';
import { token } from '@os-team/auth-mobile';

let environment: Environment;

const createRelayEnvironment = (): Environment => {
  if (!environment) {
    environment = new Environment({
      network: createRelayNetwork({
        url: 'http://192.168.0.103:4000/graphql',
        middlewares: [token],
      }),
      store: new Store(new RecordSource()),
    });
  }

  return environment;
};

export default createRelayEnvironment;

Sign out

To sign out, call the asynchronous signOut method from the useAuth hook.

Example of usage:

import React from 'react';
import { View } from 'react-native';
import { StackNavigationProp } from '@react-navigation/stack';
import Button from '@os-design-mobile/button';
import Paragraph from '@os-design-mobile/paragraph';
import { RouteProp } from '@react-navigation/native';
import { AuthenticatedStackParams } from './AuthenticatedStack';
import { useAuth } from '../../lib';

interface HomeScreenProps {
  route: RouteProp<AuthenticatedStackParams, 'Home'>;
  navigation: StackNavigationProp<AuthenticatedStackParams, 'Home'>;
}

const HomeScreen: React.FC<HomeScreenProps> = () => {
  const { signOut } = useAuth();

  return (
    <View>
      <Paragraph>Congratulations! You are signed in.</Paragraph>
      <Button
        onPress={async () => {
          await signOut();
        }}
      >
        Sign out
      </Button>
    </View>
  );
};

export default HomeScreen;
1.1.48

2 months ago

1.1.47

4 months ago

1.1.41

9 months ago

1.1.45

7 months ago

1.1.44

7 months ago

1.1.43

8 months ago

1.1.42

9 months ago

1.1.46

7 months ago

1.1.39

1 year ago

1.1.40

1 year ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.36

1 year ago

1.1.35

1 year ago

1.1.30

2 years ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.14

2 years ago

1.1.12

2 years ago

1.1.13

2 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.11

2 years ago

1.1.10

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.34

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.27

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago