diff --git a/.env.development b/.env.development index 444b872..3828d94 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,3 @@ # .env.development -EXPO_PUBLIC_API_URI="http://192.168.1.28:8000/graphql" -EXPO_PUBLIC_DEV_USER_ID=1 +API_URI="http://192.168.1.28:8000/graphql" +DEV_USER_ID=1 diff --git a/.env.production b/.env.production index dda7acd..11c7832 100644 --- a/.env.production +++ b/.env.production @@ -1,2 +1,2 @@ # .env.production -EXPO_PUBLIC_API_URI=https://api-dev.railbird.ai/graphql +API_URI=https://api-dev.railbird.ai/graphql diff --git a/App.tsx b/App.tsx index bab9923..533aa33 100644 --- a/App.tsx +++ b/App.tsx @@ -3,7 +3,7 @@ import { ClientProvider, useAuthHeader } from "./graphql/client"; import AppNavigator from "./navigation/app-navigator"; import AsyncStorage from "@react-native-async-storage/async-storage"; -import { DEV_USER_ID } from "./config"; +import { DEV_USER_ID } from "@env"; // TODO: move to different file? const SetAuthHeaderBasedOnEnv = () => { diff --git a/config.ts b/config.ts deleted file mode 100644 index 2c0b7a0..0000000 --- a/config.ts +++ /dev/null @@ -1,18 +0,0 @@ -const warnEnv = ["EXPO_PUBLIC_API_URI"]; - -const errMsg = "does not exist in the environment."; - -const missingEnv: string[] = []; - -for (const key of warnEnv) { - if (!process.env[key]) { - missingEnv.push(key); - } -} - -if (missingEnv.length > 0) { - throw new Error(`${missingEnv.join(", ")} ${errMsg}`); -} - -export const API_URI = process.env.EXPO_PUBLIC_API_URI; -export const DEV_USER_ID = process.env.EXPO_PUBLIC_DEV_USER_ID ?? false; diff --git a/env.d.tsx b/env.d.tsx index 27ab8d3..e534b18 100644 --- a/env.d.tsx +++ b/env.d.tsx @@ -1,7 +1,4 @@ -// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars -declare namespace NodeJS { - interface ProcessEnv { - EXPO_PUBLIC_API_URI: string; - EXPO_PUBLIC_DEV_USER_ID?: string; - } +declare module "@env" { + export const API_URI: string; + export const DEV_USER_ID: string; } diff --git a/graphql/client.tsx b/graphql/client.tsx index 33e88e9..7194399 100644 --- a/graphql/client.tsx +++ b/graphql/client.tsx @@ -15,7 +15,7 @@ import React, { useState, } from "react"; -import { API_URI } from "../config"; +import { API_URI } from "@env"; type Props = { children: ReactNode; diff --git a/navigation/app-navigator.tsx b/navigation/app-navigator.tsx index 8469631..32ea4ce 100644 --- a/navigation/app-navigator.tsx +++ b/navigation/app-navigator.tsx @@ -14,13 +14,13 @@ const Stack = createNativeStackNavigator(); const ScreensStack = () => ( diff --git a/package.json b/package.json index 02ca3f2..7ff3084 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { - "start": "cp .env.development .env && expo start", + "start": "NODE_ENV=development && expo start", "start:android": "expo start --android", "start:ios": "expo start --ios", "android": "expo run:android", diff --git a/screens/login.tsx b/screens/login.tsx index eb9b395..25fa450 100644 --- a/screens/login.tsx +++ b/screens/login.tsx @@ -18,7 +18,7 @@ import { import SignOutButton from "../component/buttons/sign-out"; import { useAuthHeader } from "../graphql/client"; -export default function Login() { +export default function Login({ navigation }) { const [phoneNumber, setPhoneNumber] = useState(""); const [code, setCode] = useState(""); const [user, setUser] = useState(null); @@ -33,7 +33,7 @@ export default function Login() { const token = await user.getIdToken(); if (token) { await AsyncStorage.setItem("token", token); - setAuthHeader({ key: "Authorization", value: `Bearer ${token}` }); + setAuthHeader({ key: "Authorization", value: token }); } } }); @@ -41,6 +41,8 @@ export default function Login() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + console.log(authHeader.value) + return ( Keyboard.dismiss()}> @@ -95,6 +97,7 @@ export default function Login() { Phone number: {user?.phoneNumber} +