token passed, tested with a call, change up env a bit

This commit is contained in:
Loewy 2024-02-06 13:02:15 -08:00
parent 035ce9f1b9
commit c1ba1ceb7c
9 changed files with 18 additions and 36 deletions

View File

@ -1,3 +1,3 @@
# .env.development # .env.development
EXPO_PUBLIC_API_URI="http://192.168.1.28:8000/graphql" API_URI="http://192.168.1.28:8000/graphql"
EXPO_PUBLIC_DEV_USER_ID=1 DEV_USER_ID=1

View File

@ -1,2 +1,2 @@
# .env.production # .env.production
EXPO_PUBLIC_API_URI=https://api-dev.railbird.ai/graphql API_URI=https://api-dev.railbird.ai/graphql

View File

@ -3,7 +3,7 @@ import { ClientProvider, useAuthHeader } from "./graphql/client";
import AppNavigator from "./navigation/app-navigator"; import AppNavigator from "./navigation/app-navigator";
import AsyncStorage from "@react-native-async-storage/async-storage"; 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? // TODO: move to different file?
const SetAuthHeaderBasedOnEnv = () => { const SetAuthHeaderBasedOnEnv = () => {

View File

@ -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;

View File

@ -1,7 +1,4 @@
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars declare module "@env" {
declare namespace NodeJS { export const API_URI: string;
interface ProcessEnv { export const DEV_USER_ID: string;
EXPO_PUBLIC_API_URI: string;
EXPO_PUBLIC_DEV_USER_ID?: string;
}
} }

View File

@ -15,7 +15,7 @@ import React, {
useState, useState,
} from "react"; } from "react";
import { API_URI } from "../config"; import { API_URI } from "@env";
type Props = { type Props = {
children: ReactNode; children: ReactNode;

View File

@ -14,13 +14,13 @@ const Stack = createNativeStackNavigator();
const ScreensStack = () => ( const ScreensStack = () => (
<Stack.Navigator> <Stack.Navigator>
<Stack.Screen <Stack.Screen
name="Login" name="Tabs"
component={Login} component={Tabs}
options={{ headerShown: false }} options={{ headerShown: false }}
/> />
<Stack.Screen <Stack.Screen
name="Tabs" name="Login"
component={Tabs} component={Login}
options={{ headerShown: false }} options={{ headerShown: false }}
/> />
</Stack.Navigator> </Stack.Navigator>

View File

@ -3,7 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"main": "node_modules/expo/AppEntry.js", "main": "node_modules/expo/AppEntry.js",
"scripts": { "scripts": {
"start": "cp .env.development .env && expo start", "start": "NODE_ENV=development && expo start",
"start:android": "expo start --android", "start:android": "expo start --android",
"start:ios": "expo start --ios", "start:ios": "expo start --ios",
"android": "expo run:android", "android": "expo run:android",

View File

@ -18,7 +18,7 @@ import {
import SignOutButton from "../component/buttons/sign-out"; import SignOutButton from "../component/buttons/sign-out";
import { useAuthHeader } from "../graphql/client"; import { useAuthHeader } from "../graphql/client";
export default function Login() { export default function Login({ navigation }) {
const [phoneNumber, setPhoneNumber] = useState<string>(""); const [phoneNumber, setPhoneNumber] = useState<string>("");
const [code, setCode] = useState<string>(""); const [code, setCode] = useState<string>("");
const [user, setUser] = useState<FirebaseAuthTypes.User | null>(null); const [user, setUser] = useState<FirebaseAuthTypes.User | null>(null);
@ -33,7 +33,7 @@ export default function Login() {
const token = await user.getIdToken(); const token = await user.getIdToken();
if (token) { if (token) {
await AsyncStorage.setItem("token", 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 // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
console.log(authHeader.value)
return ( return (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}> <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<View style={{ alignItems: "center" }}> <View style={{ alignItems: "center" }}>
@ -95,6 +97,7 @@ export default function Login() {
<Text>Phone number: {user?.phoneNumber}</Text> <Text>Phone number: {user?.phoneNumber}</Text>
<SignOutButton /> <SignOutButton />
<Button color="orange" title="Go to app" onPress={() => navigation.push("Tabs")} />
</> </>
)} )}
</View> </View>