From 1d85333c83d8b58a005b058eada3f097f882299e Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Fri, 4 Aug 2023 03:34:29 +0200 Subject: [PATCH] Replace use of react-native-config with process.env --- env-example | 10 +++++----- src/App.js | 5 ++--- src/api.js | 10 ++++------ src/modules/events/useEventList.js | 3 +-- src/modules/login/Login.js | 3 +-- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/env-example b/env-example index d3135f8..55f8f9e 100644 --- a/env-example +++ b/env-example @@ -1,5 +1,5 @@ -EVENT_API_URL=https://studentersamfundet.no -DUSKEN_API_URL=https://galtinn.neuf.no -DUSKEN_FORGOT_PASSWORD_URL=https://galtinn.neuf.no/auth/password_reset/ -SENTRY_DSN= -STRIPE_PUBLISHABLE_KEY= +EXPO_PUBLIC_EVENT_API_URL=https://studentersamfundet.no +EXPO_PUBLIC_DUSKEN_API_URL=https://galtinn.neuf.no +EXPO_PUBLIC_DUSKEN_FORGOT_PASSWORD_URL=https://galtinn.neuf.no/auth/password_reset/ +EXPO_PUBLIC_SENTRY_DSN= +EXPO_PUBLIC_STRIPE_PUBLISHABLE_KEY= diff --git a/src/App.js b/src/App.js index a320209..8bb6c0c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,6 @@ import React from 'react'; import { Provider } from 'react-redux'; import { PersistGate } from 'redux-persist/integration/react'; -import Config from 'react-native-config'; import { ApolloClient, HttpLink, InMemoryCache, ApolloProvider } from '@apollo/client'; import { StripeProvider } from '@stripe/stripe-react-native'; @@ -9,7 +8,7 @@ import Dusken from './Dusken'; import { store, persistor } from './reduxStore'; const apolloClient = new ApolloClient({ - link: new HttpLink({ uri: `${Config.DUSKEN_API_URL}/api/graphql/` }), + link: new HttpLink({ uri: `${process.env.EXPO_PUBLIC_DUSKEN_API_URL}/api/graphql/` }), cache: new InMemoryCache(), }); @@ -20,7 +19,7 @@ export default function App() { {/* FIXME: Read urlScheme and merchantIdentifier from .Config */} diff --git a/src/api.js b/src/api.js index 2b34396..bb1af04 100644 --- a/src/api.js +++ b/src/api.js @@ -1,5 +1,3 @@ -import Config from 'react-native-config'; - import { loginFailure, loginRequest, @@ -21,7 +19,7 @@ export function requestLogin(username, password) { // We are now logging in dispatch(loginRequest()); - return fetchWithTimeout(`${Config.DUSKEN_API_URL}/auth/obtain-token/`, { + return fetchWithTimeout(`${process.env.EXPO_PUBLIC_DUSKEN_API_URL}/auth/obtain-token/`, { method: 'POST', headers: { Accept: 'application/json', @@ -56,7 +54,7 @@ export function requestUserData(authToken) { // We are now fetching user data dispatch(userDataRequest()); - return fetchWithTimeout(`${Config.DUSKEN_API_URL}/api/me/`, { + return fetchWithTimeout(`${process.env.EXPO_PUBLIC_DUSKEN_API_URL}/api/me/`, { method: 'GET', headers: { Accept: 'application/json', @@ -86,7 +84,7 @@ export function requestRegisterUser({ firstName, lastName, email, phoneNumber, p return (dispatch) => { dispatch(registerUserRequest()); - return fetchWithTimeout(`${Config.DUSKEN_API_URL}/api/user/register/`, { + return fetchWithTimeout(`${process.env.EXPO_PUBLIC_DUSKEN_API_URL}/api/user/register/`, { method: 'POST', headers: { Accept: 'application/json', @@ -122,7 +120,7 @@ export function requestMembershipCharge(authToken, stripeToken, membershipType) return (dispatch) => { dispatch(membershipChargeRequest()); - return fetchWithTimeout(`${Config.DUSKEN_API_URL}/api/membership/charge/`, { + return fetchWithTimeout(`${process.env.EXPO_PUBLIC_DUSKEN_API_URL}/api/membership/charge/`, { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/modules/events/useEventList.js b/src/modules/events/useEventList.js index e8fc476..23c01da 100644 --- a/src/modules/events/useEventList.js +++ b/src/modules/events/useEventList.js @@ -1,5 +1,4 @@ import { useEffect, useState } from 'react'; -import Config from 'react-native-config'; import moment from 'moment'; import 'moment/locale/nb'; @@ -56,7 +55,7 @@ const useEventList = () => { }; const fetchEvents = async () => { - const url = `${Config.EVENT_API_URL}/wp-json/wp/v2/events?page=${page}&future=1`; + const url = `${process.env.EXPO_PUBLIC_EVENT_API_URL}/wp-json/wp/v2/events?page=${page}&future=1`; setLoading(true); let eventData; diff --git a/src/modules/login/Login.js b/src/modules/login/Login.js index c60d395..32b9c8f 100644 --- a/src/modules/login/Login.js +++ b/src/modules/login/Login.js @@ -1,7 +1,6 @@ import React from 'react'; import { Linking, StyleSheet, View } from 'react-native'; import { ScrollView, Spinner, Button, Text } from 'native-base'; -import Config from 'react-native-config'; import theme from '../../theme'; import useLogin from './useLogin'; @@ -44,7 +43,7 @@ const Login = () => { small light onPress={() => { - Linking.openURL(Config.DUSKEN_FORGOT_PASSWORD_URL); + Linking.openURL(process.env.EXPO_PUBLIC_DUSKEN_FORGOT_PASSWORD_URL); }} style={styles.forgotPasswordButton} >