@passageidentity/passage-react-native
Version:
Passkey Complete for React Native - Go completely passwordless with a standalone auth solution in your React Native app with Passage by 1Password
44 lines (43 loc) • 2.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _configPlugins = require("@expo/config-plugins");
var fs = _interopRequireWildcard(require("fs"));
var path = _interopRequireWildcard(require("path"));
require("dotenv/config");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const modifyAndroidStringsXML = configuration => {
console.log('Passage: Checking Android strings.xml for required asset statement.');
const associatedDomain = process.env.ASSOCIATED_DOMAIN;
if (!associatedDomain) {
console.error('Passage: ASSOCIATED_DOMAIN is not defined in your .env. This is required for Passage.');
return configuration;
}
return (0, _configPlugins.withDangerousMod)(configuration, ['android', config => {
const stringsXmlPath = path.join(config.modRequest.platformProjectRoot, 'app/src/main/res/values/strings.xml');
if (!fs.existsSync(stringsXmlPath)) {
console.warn(`Passage: strings.xml not found at ${stringsXmlPath}. Skipping modification.`);
return config;
}
let stringsXmlContent = fs.readFileSync(stringsXmlPath, 'utf-8');
if (!stringsXmlContent.includes('<string name="asset_statements">')) {
console.log('Passage: Adding required asset_statements string.');
const newStrings = `<string name="passage_auth_origin">${associatedDomain}</string>
<string name="asset_statements">[{"include": "https://@string/passage_auth_origin/.well-known/assetlinks.json"}]</string>`;
stringsXmlContent = stringsXmlContent.replace('</resources>', `${newStrings}\n</resources>`);
} else {
console.log('Passage: Updating required asset_statements string.');
const regex = /<string name="passage_auth_origin">.*?<\/string>/;
const newDomainString = `<string name="passage_auth_origin">${associatedDomain}</string>`;
stringsXmlContent = stringsXmlContent.replace(regex, newDomainString);
}
fs.writeFileSync(stringsXmlPath, stringsXmlContent);
console.log('Passage: strings.xml check complete.');
return config;
}]);
};
var _default = exports.default = modifyAndroidStringsXML;
//# sourceMappingURL=modifyAndroidStringsXML.js.map