diff --git a/App.tsx b/App.tsx index 57ac640..bab9923 100644 --- a/App.tsx +++ b/App.tsx @@ -2,14 +2,13 @@ import React, { useEffect } from "react"; import { ClientProvider, useAuthHeader } from "./graphql/client"; import AppNavigator from "./navigation/app-navigator"; -import { DEV_USER_ID } from "./config"; import AsyncStorage from "@react-native-async-storage/async-storage"; +import { DEV_USER_ID } from "./config"; // TODO: move to different file? const SetAuthHeaderBasedOnEnv = () => { const { setAuthHeader } = useAuthHeader(); - useEffect(() => { const setAuthAsync = async () => { if (DEV_USER_ID) { @@ -17,7 +16,7 @@ const SetAuthHeaderBasedOnEnv = () => { setAuthHeader({ key: "user_id", value: DEV_USER_ID }); } else { // Fetch token for authenticated users in production - const token = await AsyncStorage.getItem('token'); // get from not firebase auth ASYNC + const token = await AsyncStorage.getItem("token"); // get from not firebase auth ASYNC if (token) { console.log("Setting firebase auth token"); setAuthHeader({ key: "Authorization", value: `Bearer ${token}` }); diff --git a/auth/firebase-auth.tsx b/auth/firebase-auth.tsx index aadca16..732b171 100644 --- a/auth/firebase-auth.tsx +++ b/auth/firebase-auth.tsx @@ -1,45 +1,53 @@ -import AsyncStorage from '@react-native-async-storage/async-storage'; -import auth, { FirebaseAuthTypes } from '@react-native-firebase/auth'; -import { Alert } from 'react-native'; +import AsyncStorage from "@react-native-async-storage/async-storage"; +import auth, { FirebaseAuthTypes } from "@react-native-firebase/auth"; +import { Alert } from "react-native"; -export const handleSignInWithPhoneNumber = async (phoneNumber: string): Promise => { - if (!phoneNumber) { - Alert.alert("Please enter a valid phone number with a country code"); - return; - } - try { - const confirmation = await auth().signInWithPhoneNumber(phoneNumber); - return confirmation; - } catch (err) { - console.warn(err); - Alert.alert("There was an error. Make sure you are using a country code (ex: +1 for US)"); - } +export const handleSignInWithPhoneNumber = async ( + phoneNumber: string, +): Promise => { + if (!phoneNumber) { + Alert.alert("Please enter a valid phone number with a country code"); + return; + } + try { + const confirmation = await auth().signInWithPhoneNumber(phoneNumber); + return confirmation; + } catch (err) { + console.warn(err); + Alert.alert( + "There was an error. Make sure you are using a country code (ex: +1 for US)", + ); + } }; -export const confirmCode = async (confirm: FirebaseAuthTypes.ConfirmationResult, code: string): Promise => { - try { - await confirm.confirm(code); - } catch { - Alert.alert("Invalid code, please try again."); - } +export const confirmCode = async ( + confirm: FirebaseAuthTypes.ConfirmationResult, + code: string, +): Promise => { + try { + await confirm.confirm(code); + } catch { + Alert.alert("Invalid code, please try again."); + } }; -// TODO: eslint not detecting ts? -// eslint-disable-next-line no-unused-vars -export const onAuthStateChanged = (callback: (user: FirebaseAuthTypes.User | null) => void) => { - return auth().onAuthStateChanged(callback); +export const onAuthStateChanged = ( + // TODO: eslint not detecting ts? + // eslint-disable-next-line no-unused-vars + callback: (user: FirebaseAuthTypes.User | null) => void, +) => { + return auth().onAuthStateChanged(callback); }; - export const getCurrentUserToken = async (): Promise => { - const user = auth().currentUser; - if (user) { - return await user.getIdToken(); - } - return null; + const user = auth().currentUser; + if (user) { + return await user.getIdToken(); + } + return null; }; export const handleSignOut = async (): Promise => { - await AsyncStorage.removeItem('token'); - await auth().signOut() -} \ No newline at end of file + await AsyncStorage.removeItem("token"); + await auth().signOut(); +}; diff --git a/auth/index.ts b/auth/index.ts index da5fffd..89b62ac 100644 --- a/auth/index.ts +++ b/auth/index.ts @@ -1,15 +1,15 @@ import { - handleSignInWithPhoneNumber, - confirmCode, - onAuthStateChanged, - getCurrentUserToken, - handleSignOut -} from './firebase-auth' + confirmCode, + getCurrentUserToken, + handleSignInWithPhoneNumber, + handleSignOut, + onAuthStateChanged, +} from "./firebase-auth"; export { - handleSignInWithPhoneNumber, - confirmCode, - onAuthStateChanged, - getCurrentUserToken, - handleSignOut -} \ No newline at end of file + confirmCode, + getCurrentUserToken, + handleSignInWithPhoneNumber, + handleSignOut, + onAuthStateChanged, +}; diff --git a/component/buttons/sign-out.tsx b/component/buttons/sign-out.tsx index 2cc37d8..3c65bca 100644 --- a/component/buttons/sign-out.tsx +++ b/component/buttons/sign-out.tsx @@ -1,18 +1,18 @@ -import { handleSignOut } from "../../auth" -import { useAuthHeader } from "../../graphql/client" -import React from "react" -import { Button } from "react-native" +import React from "react"; +import { Button } from "react-native"; +import { handleSignOut } from "../../auth"; +import { useAuthHeader } from "../../graphql/client"; export default function SignOutButton(): React.JSX.Element { - const { setAuthHeader } = useAuthHeader() + const { setAuthHeader } = useAuthHeader(); - return ( -