Repository navigation
Expand file tree
/
Copy pathwithAuth0AndroidCallbacks.js
More file actions
48 lines (43 loc) · 1.63 KB
/
Copy pathwithAuth0AndroidCallbacks.js
File metadata and controls
48 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { AndroidConfig, withAndroidManifest } = require("@expo/config-plugins");
module.exports = function withAuth0AndroidCallbacks(config) {
// Manifest mods run in reverse plugin order. Register this before Auth0 so
// Auth0 has added RedirectActivity before this mod adjusts MainActivity.
return withAndroidManifest(config, (config) => {
const application = AndroidConfig.Manifest.getMainApplicationOrThrow(
config.modResults,
);
const redirectActivity = application.activity?.find(
(activity) =>
activity.$["android:name"] ===
"com.auth0.android.provider.RedirectActivity",
);
if (!redirectActivity) {
throw new Error(
"List withAuth0AndroidCallbacks before react-native-auth0 in the Expo plugins.",
);
}
const callbackSchemes = new Set(
(redirectActivity["intent-filter"] ?? []).flatMap((filter) =>
(filter.data ?? []).map((data) => data.$["android:scheme"]),
),
);
const mainActivity = AndroidConfig.Manifest.getMainActivityOrThrow(
config.modResults,
);
// The generic app scheme also matches Auth0 URLs. Lower only the broad
// filter's priority so Android sends callbacks to Auth0's specific filter.
// Regular app and development links still resolve to MainActivity.
for (const filter of mainActivity["intent-filter"] ?? []) {
if (
(filter.data ?? []).some(
(data) =>
callbackSchemes.has(data.$["android:scheme"]) &&
!data.$["android:host"],
)
) {
filter.$ = { ...filter.$, "android:priority": "-1" };
}
}
return config;
});
};