Skip to content

Commit

Permalink
Use dotenv to manage secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Sep 5, 2018
1 parent 230b54d commit 100ac38
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 45 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"presets": ["flow", "react-native"],
"presets": ["flow", "react-native", "react-native-dotenv"],
"env": {
"development": {
"plugins": [
"transform-react-jsx-source",
"transform-inline-environment-variables"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/node_modules

# misc
.env
.env.local
.env.development.local
.env.test.local
Expand Down
28 changes: 11 additions & 17 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {
createBottomTabNavigator,
} from 'react-navigation';

import {
STREAM_API_KEY,
STREAM_API_TOKEN,
STREAM_APP_ID,
} from 'react-native-dotenv';

import Icon from './components/Icon';
import HomeScreen from './screens/HomeScreen';
import SearchScreen from './screens/SearchScreen';
Expand Down Expand Up @@ -96,24 +102,12 @@ const Navigation = createStackNavigator({
});

const App = () => {
let apiKey = process.env['STREAM_API_KEY'];
let appId = process.env['STREAM_APP_ID'];
let token = process.env['STREAM_TOKEN'];

if (!apiKey) {
console.error('STREAM_API_KEY should be set');
return null;
}
let apiKey = STREAM_API_KEY;
let appId = STREAM_APP_ID;
let token = STREAM_API_TOKEN;

if (!appId) {
console.error('STREAM_APP_ID should be set');
return null;
}

if (!token) {
console.error('STREAM_TOKEN should be set');
return null;
}
// IMPORTANT: This token is should normally be generated server side, so the
// client doesn't have access to the master secret.

// eslint-disable-next-line no-unused-vars
function example() {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"babel-preset-env": "^1.7.0",
"babel-preset-flow": "^6.23.0",
"dotenv": "^6.0.0",
"eslint": "^5.1.0",
"eslint-plugin-flowtype": "^2.29.1",
"eslint-plugin-jest": "^21.17.0",
Expand Down Expand Up @@ -51,12 +52,12 @@
"babel-plugin-module-resolver": "^3.1.1",
"babel-preset-expo": "^4.0.0",
"expo": "^27.0.1",
"expo-activity-feed": "^0.5.15",
"faker": "^4.1.0",
"numeral": "^2.0.6",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-activity-feed-core": "link:..",
"expo-activity-feed": "link:../expo-package",
"react-native-dotenv": "^0.2.0",
"react-native-keyboard-aware-scroll-view": "^0.5.0",
"react-navigation": "^2.3.1"
}
Expand Down
40 changes: 25 additions & 15 deletions scripts/initData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ import faker from 'faker';

import type { UserSession, CloudClient } from '../types';

import dotenv from 'dotenv';
dotenv.config();

async function main() {
let apiKey = process.env['STREAM_API_KEY'] || '';
let apiSecret = process.env['STREAM_API_SECRET'] || '';
let appId = process.env['STREAM_APP_ID'] || '';
let apiUrl = process.env['STREAM_API_URL'];

console.log(apiKey, apiSecret, apiUrl);
let client: CloudClient = stream.connectCloud(apiKey, appId, {
urlOverride: {
api: apiUrl,
},
keepAlive: false,
});
let apiKey = process.env.STREAM_API_KEY;
let apiSecret = process.env.STREAM_API_SECRET;
let appId = process.env.STREAM_APP_ID;
if (!apiKey) {
console.error('STREAM_API_KEY should be set');
return;
}

if (!appId) {
console.error('STREAM_APP_ID should be set');
return;
}

if (!apiSecret) {
console.error('STREAM_SECRET should be set');
return;
}

let client: CloudClient = stream.connectCloud(apiKey, appId);

function createUserSession(userId): UserSession {
return client.createUserSession(
Expand All @@ -30,6 +40,9 @@ async function main() {
let league = createUserSession('justiceleague');
let bowie = createUserSession('davidbowie');

console.log('Add the following line to your .env file');
console.log('STREAM_API_TOKEN=' + batman.token);

await batman.user.getOrCreate({
name: 'Batman',
url: 'batsignal.com',
Expand Down Expand Up @@ -160,9 +173,6 @@ async function main() {
withOwnReactions: true,
withRecentReactions: true,
});
console.log(response.results[0].reaction_counts);
console.log(response.results[0].own_reactions);
console.log(response.results[0].latest_reactions);

await ignore409(() =>
Promise.all(
Expand Down
47 changes: 38 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,12 @@ babel-plugin-check-es2015-constants@^6.22.0, babel-plugin-check-es2015-constants
dependencies:
babel-runtime "^6.22.0"

babel-plugin-dotenv@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/babel-plugin-dotenv/-/babel-plugin-dotenv-0.1.1.tgz#9c8faea67a7c034fe7e94099187ab2e7573400bc"
dependencies:
dotenv "^2.0.0"

babel-plugin-external-helpers@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-external-helpers/-/babel-plugin-external-helpers-6.22.0.tgz#2285f48b02bd5dede85175caf8c62e86adccefa1"
Expand Down Expand Up @@ -2770,6 +2776,14 @@ dot-case@^1.1.0:
dependencies:
sentence-case "^1.1.2"

dotenv@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-2.0.0.tgz#bd759c357aaa70365e01c96b7b0bec08a6e0d949"

dotenv@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.0.0.tgz#24e37c041741c5f4b25324958ebbc34bca965935"

duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
Expand Down Expand Up @@ -3121,9 +3135,11 @@ expect@^22.4.0:
jest-message-util "^22.4.3"
jest-regex-util "^22.4.3"

"expo-activity-feed@link:../expo-package":
version "0.0.0"
uid ""
expo-activity-feed@^0.5.15:
version "0.5.15"
resolved "https://registry.yarnpkg.com/expo-activity-feed/-/expo-activity-feed-0.5.15.tgz#b6ba54190a1749f0bd31a87b57f38292d6f786ee"
dependencies:
react-native-activity-feed-core "0.5.15"

expo@^27.0.1:
version "27.1.1"
Expand Down Expand Up @@ -6436,12 +6452,19 @@ react-lifecycles-compat@^3, react-lifecycles-compat@^3.0.4:
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

react-native-activity-feed-core@0.5.15:
version "0.0.0"
uid ""

"react-native-activity-feed-core@link:..":
version "0.0.0"
uid ""
version "0.5.15"
resolved "https://registry.yarnpkg.com/react-native-activity-feed-core/-/react-native-activity-feed-core-0.5.15.tgz#b787168fe897fdd784f001b8b7cbecbd26a6bbd3"
dependencies:
es6-symbol "^3.1.1"
faker "^4.1.0"
getstream "3.21.0-beta.7"
immutable "^4.0.0-rc.9"
moment "^2.22.2"
numeral "^2.0.6"
react-native-keyboard-spacer "^0.4.1"
react-native-sticky-keyboard-accessory "^0.1.1"
stream-analytics "^2.7.1"
url-parse "^1.4.3"

react-native-branch@2.0.0-beta.3:
version "2.0.0-beta.3"
Expand All @@ -6451,6 +6474,12 @@ react-native-dismiss-keyboard@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-native-dismiss-keyboard/-/react-native-dismiss-keyboard-1.0.0.tgz#32886242b3f2317e121f3aeb9b0a585e2b879b49"

react-native-dotenv@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-0.2.0.tgz#311551cb6a35a3dcfede648bded55c0e3ece579d"
dependencies:
babel-plugin-dotenv "0.1.1"

react-native-drawer-layout-polyfill@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/react-native-drawer-layout-polyfill/-/react-native-drawer-layout-polyfill-1.3.2.tgz#192c84d7a5a6b8a6d2be2c7daa5e4164518d0cc7"
Expand Down

0 comments on commit 100ac38

Please sign in to comment.