diff --git a/.gitignore b/.gitignore index 20e8222..0a27a65 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,5 @@ android/keystores/debug.keystore lib/ example/.yarn + +.env diff --git a/example/babel.config.js b/example/babel.config.js index d9addbb..9c65c70 100644 --- a/example/babel.config.js +++ b/example/babel.config.js @@ -1,9 +1,16 @@ const path = require('path'); const pak = require('../package.json'); - module.exports = { presets: ['module:@react-native/babel-preset'], plugins: [ + [ + 'module:react-native-dotenv', + { + envName: 'APP_ENV', + moduleName: '@env', + path: '.env', + }, + ], [ 'module-resolver', { diff --git a/example/package.json b/example/package.json index f76ca2d..58b75a5 100644 --- a/example/package.json +++ b/example/package.json @@ -20,7 +20,8 @@ "@react-native/babel-preset": "0.74.83", "@react-native/metro-config": "0.74.83", "@react-native/typescript-config": "0.74.83", - "babel-plugin-module-resolver": "^5.0.0" + "babel-plugin-module-resolver": "^5.0.0", + "react-native-dotenv": "^3.4.11" }, "engines": { "node": ">=18" diff --git a/example/src/App.tsx b/example/src/App.tsx index 5dbe375..0fe5fae 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -2,18 +2,32 @@ import * as React from 'react'; import { CryptrProvider } from '@cryptr/cryptr-react-native'; import type { CryptrConfig } from '../../src/utils/interfaces'; import HomeScreen from './screens/HomeScreen'; +import { + REACT_APP_CRYPTR_ACCOUNT_DOMAIN, + REACT_APP_CRYPTR_CLIENT_ID, + REACT_APP_CRYPTR_SERVICE_URL, + REACT_APP_CRYPTR_AUDIENCE, + REACT_APP_CRYPTR_DEFAULT_REDIRECT_URI, + REACT_APP_CRYPTR_DEDICATED_SERVER, + REACT_APP_CRYPTR_NO_POPUP_NO_COOKIE, + REACT_APP_CRYPTR_DEFAULT_LOCALE, +} from '@env'; const config: CryptrConfig = { - accountDomain: 'account-domain', - clientId: 'client-id', - cryptrServiceUrl: 'https://cryptr-service.ul', - audience: 'cryptr://2024-app', - defaultRedirectUri: 'cryptr://2024-app', - dedicatedServer: true, - noPopupNoCookie: true, - defaultLocale: 'en', + accountDomain: REACT_APP_CRYPTR_ACCOUNT_DOMAIN, + clientId: REACT_APP_CRYPTR_CLIENT_ID, + cryptrServiceUrl: REACT_APP_CRYPTR_SERVICE_URL, + audience: REACT_APP_CRYPTR_AUDIENCE, + defaultRedirectUri: REACT_APP_CRYPTR_DEFAULT_REDIRECT_URI, + dedicatedServer: REACT_APP_CRYPTR_DEDICATED_SERVER, + noPopupNoCookie: REACT_APP_CRYPTR_NO_POPUP_NO_COOKIE, + defaultLocale: REACT_APP_CRYPTR_DEFAULT_LOCALE, }; +console.debug(config); +console.debug(REACT_APP_CRYPTR_ACCOUNT_DOMAIN); +console.debug(process.env); + export default function App() { return ( diff --git a/example/yarn.lock b/example/yarn.lock index 76b775a..b604464 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -1635,6 +1635,7 @@ __metadata: babel-plugin-module-resolver: ^5.0.0 react: 18.2.0 react-native: 0.74.1 + react-native-dotenv: ^3.4.11 languageName: unknown linkType: soft @@ -3147,6 +3148,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.4.5": + version: 16.4.5 + resolution: "dotenv@npm:16.4.5" + checksum: 301a12c3d44fd49888b74eb9ccf9f07a1f5df43f489e7fcb89647a2edcd84c42d6bc349dc8df099cd18f07c35c7b04685c1a4f3e6a6a9e6b30f8d48c15b7f49c + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" @@ -5360,6 +5368,17 @@ __metadata: languageName: node linkType: hard +"react-native-dotenv@npm:^3.4.11": + version: 3.4.11 + resolution: "react-native-dotenv@npm:3.4.11" + dependencies: + dotenv: ^16.4.5 + peerDependencies: + "@babel/runtime": ^7.20.6 + checksum: 3ebac2c2ed79dd7e4920fd3fc2da9187413b7190231618e4858b46c47833677838b96d531afe7bd5c4b0a60454dba40cb8708722210df5d522e30aefbf41da05 + languageName: node + linkType: hard + "react-native@npm:0.74.1": version: 0.74.1 resolution: "react-native@npm:0.74.1"