2024-02-05 23:50:24 -07:00
|
|
|
import React, { useEffect } from "react";
|
2024-02-06 16:08:19 -07:00
|
|
|
import { ClientProvider, useAuthHeader } from "./src/graphql/client";
|
|
|
|
import AppNavigator from "./src/navigation/app-navigator";
|
2024-02-03 18:23:46 -07:00
|
|
|
|
2024-02-06 14:02:15 -07:00
|
|
|
import { DEV_USER_ID } from "@env";
|
2024-02-06 14:03:44 -07:00
|
|
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
2024-02-07 11:57:32 -07:00
|
|
|
import Loading from "./src/lib/loading";
|
2024-02-03 18:23:46 -07:00
|
|
|
|
2024-02-06 12:09:22 -07:00
|
|
|
// TODO: move to different file?
|
2024-02-03 18:23:46 -07:00
|
|
|
const SetAuthHeaderBasedOnEnv = () => {
|
|
|
|
const { setAuthHeader } = useAuthHeader();
|
|
|
|
|
2024-02-05 23:50:24 -07:00
|
|
|
useEffect(() => {
|
|
|
|
const setAuthAsync = async () => {
|
2024-02-06 00:58:39 -07:00
|
|
|
if (DEV_USER_ID) {
|
|
|
|
console.log("Setting fake authorization user to: ", DEV_USER_ID);
|
|
|
|
setAuthHeader({ key: "user_id", value: DEV_USER_ID });
|
|
|
|
} else {
|
|
|
|
// Fetch token for authenticated users in production
|
2024-02-06 12:34:52 -07:00
|
|
|
const token = await AsyncStorage.getItem("token"); // get from not firebase auth ASYNC
|
2024-02-06 00:58:39 -07:00
|
|
|
if (token) {
|
|
|
|
console.log("Setting firebase auth token");
|
|
|
|
setAuthHeader({ key: "Authorization", value: `Bearer ${token}` });
|
2024-02-06 12:09:22 -07:00
|
|
|
}
|
2024-02-05 23:50:24 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setAuthAsync();
|
2024-02-03 18:23:46 -07:00
|
|
|
}, [setAuthHeader]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
2024-01-06 18:51:59 -07:00
|
|
|
|
|
|
|
const App: React.FC = () => {
|
2024-01-06 19:25:17 -07:00
|
|
|
return (
|
2024-01-31 16:55:33 -07:00
|
|
|
<ClientProvider>
|
2024-02-07 11:57:32 -07:00
|
|
|
<Loading>
|
|
|
|
<SetAuthHeaderBasedOnEnv />
|
|
|
|
<AppNavigator />
|
|
|
|
</Loading>
|
2024-01-31 16:55:33 -07:00
|
|
|
</ClientProvider>
|
2024-01-06 19:25:17 -07:00
|
|
|
);
|
2024-01-06 18:51:59 -07:00
|
|
|
};
|
|
|
|
|
2024-01-06 23:58:54 -07:00
|
|
|
export default function Root() {
|
|
|
|
return (
|
|
|
|
<React.StrictMode>
|
|
|
|
<App />
|
|
|
|
</React.StrictMode>
|
|
|
|
);
|
|
|
|
}
|