Skip to content

Commit 3f0ea30

Browse files
committed
chore(example): derive OS API Key from .env
1 parent 52e6fa9 commit 3f0ea30

7 files changed

Lines changed: 27 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OneSignal REST API Key (get from OneSignal dashboard)
2+
REST_API_KEY=your_rest_api_key_here

examples/RNOneSignalTS/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ node_modules/
4141
npm-debug.log
4242
yarn-error.log
4343

44+
# Environment variables
45+
.env
46+
.env.local
47+
.env.*.local
48+
4449
# fastlane
4550
#
4651
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
module.exports = {
22
presets: ['module:@react-native/babel-preset'],
3+
plugins: [
4+
[
5+
'module:react-native-dotenv',
6+
{
7+
moduleName: '@env',
8+
path: '.env',
9+
safe: false,
10+
allowUndefined: true,
11+
},
12+
],
13+
],
314
};

examples/RNOneSignalTS/bun.lockb

759 Bytes
Binary file not shown.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { REST_API_KEY as ENV_REST_API_KEY } from '@env';
2+
13
export const APP_ID = '77e32082-ea27-42e3-a898-c72e141824ef';
24

35
// WARNING: Storing API keys in client code is NOT SAFE for production.
46
// In production apps, make API calls from your backend server.
57
// This is for demo purposes only.
6-
export const REST_API_KEY = ''; // Replace with your OneSignal REST API Key
8+
export const REST_API_KEY = ENV_REST_API_KEY || '';
79
export const ONESIGNAL_API_URL = 'https://onesignal.com/api/v1/notifications';

examples/RNOneSignalTS/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"preios": "bun run setup && bun run update:pod",
1010
"android": "react-native run-android",
1111
"ios": "react-native run-ios",
12-
"start": "react-native start"
12+
"start": "react-native start",
13+
"start:fresh": "react-native start --reset-cache"
1314
},
1415
"dependencies": {
1516
"@react-native/new-app-screen": "0.82.1",
@@ -34,6 +35,7 @@
3435
"@types/react": "^19.2.7",
3536
"@types/react-test-renderer": "^19.1.0",
3637
"prettier": "3.7.4",
38+
"react-native-dotenv": "^3.4.11",
3739
"react-test-renderer": "19.2.1",
3840
"typescript": "^5.9.3"
3941
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module '@env' {
2+
export const REST_API_KEY: string;
3+
}

0 commit comments

Comments
 (0)