Skip to content

Make react-native sdk friendly for Expo build #372

Description

@IniZio

Expo is now the official recommendation according to React Native's documentation

In order to make Authgear work with Expo's Android build, currently we need to implement a custom plugin:

// src/plugins/authgear-plugin.ts
import { ConfigPlugin, withAndroidManifest } from "expo/config-plugins";

const withAuthgearOAuth: ConfigPlugin = (config) => {
  return withAndroidManifest(config, (config) => {
    const mainApplication = config.modResults.manifest.application?.[0];
    if (mainApplication == null) {
      return config;
    }

    mainApplication.activity ??= [];

    mainApplication.activity.push({
      $: {
        "android:name": "com.authgear.reactnative.OAuthRedirectActivity",
        "android:exported": "true",
        "android:launchMode": "singleTask",
      },
      "intent-filter": [
        {
          action: [
            {
              $: {
                "android:name": "android.intent.action.VIEW",
              },
            },
          ],
          category: [
            {
              $: {
                "android:name": "android.intent.category.DEFAULT",
              },
            },
            {
              $: {
                "android:name": "android.intent.category.BROWSABLE",
              },
            },
          ],
          data: [
            {
              $: {
                "android:scheme": config.android?.package,
                "android:host": "authgear",
                "android:pathPrefix": "/proceed",
              },
            },
          ],
        },
      ],
    });

    return config;
  });
};

export default withAuthgearOAuth;

And include in app.config.ts

export default ({ config }: ConfigContext): ExpoConfig => {
  return {
    // ...other configs
    plugins: [
      // ... other plugins
      "./src/plugins/authgear-oauth-plugin.ts",
    ],
  };
};

Wonder if it can be included as official plugin for easier integration? Then it can be installed with expo install

Note that manifest merging is also possible (https://docs.expo.dev/config-plugins/development-and-debugging/#modify-androidmanifestxml) but I didn't experiment with it.

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions