fix prettier conflicts
This commit is contained in:
parent
eb2534ff94
commit
035ce9f1b9
5
App.tsx
5
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}` });
|
||||
|
@ -1,8 +1,10 @@
|
||||
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<FirebaseAuthTypes.ConfirmationResult | undefined> => {
|
||||
export const handleSignInWithPhoneNumber = async (
|
||||
phoneNumber: string,
|
||||
): Promise<FirebaseAuthTypes.ConfirmationResult | undefined> => {
|
||||
if (!phoneNumber) {
|
||||
Alert.alert("Please enter a valid phone number with a country code");
|
||||
return;
|
||||
@ -12,11 +14,16 @@ export const handleSignInWithPhoneNumber = async (phoneNumber: string): Promise<
|
||||
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)");
|
||||
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<void> => {
|
||||
export const confirmCode = async (
|
||||
confirm: FirebaseAuthTypes.ConfirmationResult,
|
||||
code: string,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await confirm.confirm(code);
|
||||
} catch {
|
||||
@ -24,13 +31,14 @@ export const confirmCode = async (confirm: FirebaseAuthTypes.ConfirmationResult,
|
||||
}
|
||||
};
|
||||
|
||||
export const onAuthStateChanged = (
|
||||
// TODO: eslint not detecting ts?
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export const onAuthStateChanged = (callback: (user: FirebaseAuthTypes.User | null) => void) => {
|
||||
callback: (user: FirebaseAuthTypes.User | null) => void,
|
||||
) => {
|
||||
return auth().onAuthStateChanged(callback);
|
||||
};
|
||||
|
||||
|
||||
export const getCurrentUserToken = async (): Promise<string | null> => {
|
||||
const user = auth().currentUser;
|
||||
if (user) {
|
||||
@ -40,6 +48,6 @@ export const getCurrentUserToken = async (): Promise<string | null> => {
|
||||
};
|
||||
|
||||
export const handleSignOut = async (): Promise<void> => {
|
||||
await AsyncStorage.removeItem('token');
|
||||
await auth().signOut()
|
||||
}
|
||||
await AsyncStorage.removeItem("token");
|
||||
await auth().signOut();
|
||||
};
|
||||
|
@ -1,15 +1,15 @@
|
||||
import {
|
||||
handleSignInWithPhoneNumber,
|
||||
confirmCode,
|
||||
onAuthStateChanged,
|
||||
getCurrentUserToken,
|
||||
handleSignOut
|
||||
} from './firebase-auth'
|
||||
handleSignInWithPhoneNumber,
|
||||
handleSignOut,
|
||||
onAuthStateChanged,
|
||||
} from "./firebase-auth";
|
||||
|
||||
export {
|
||||
handleSignInWithPhoneNumber,
|
||||
confirmCode,
|
||||
onAuthStateChanged,
|
||||
getCurrentUserToken,
|
||||
handleSignOut
|
||||
}
|
||||
handleSignInWithPhoneNumber,
|
||||
handleSignOut,
|
||||
onAuthStateChanged,
|
||||
};
|
||||
|
@ -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 (
|
||||
<Button
|
||||
title={'Sign out'}
|
||||
title={"Sign out"}
|
||||
onPress={async () => {
|
||||
setAuthHeader({ key: 'Authorization', value: '' })
|
||||
await handleSignOut()
|
||||
setAuthHeader({ key: "Authorization", value: "" });
|
||||
await handleSignOut();
|
||||
}}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
const warnEnv = [
|
||||
'EXPO_PUBLIC_API_URI'
|
||||
];
|
||||
const warnEnv = ["EXPO_PUBLIC_API_URI"];
|
||||
|
||||
const errMsg =
|
||||
'does not exist in the environment.';
|
||||
const errMsg = "does not exist in the environment.";
|
||||
|
||||
const missingEnv: string[] = [];
|
||||
|
||||
@ -14,7 +11,7 @@ for (const key of warnEnv) {
|
||||
}
|
||||
|
||||
if (missingEnv.length > 0) {
|
||||
throw new Error(`${missingEnv.join(', ')} ${errMsg}`);
|
||||
throw new Error(`${missingEnv.join(", ")} ${errMsg}`);
|
||||
}
|
||||
|
||||
export const API_URI = process.env.EXPO_PUBLIC_API_URI;
|
||||
|
@ -15,7 +15,7 @@ import React, {
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { API_URI } from '../config'
|
||||
import { API_URI } from "../config";
|
||||
|
||||
type Props = {
|
||||
children: ReactNode;
|
||||
|
@ -1,5 +1,7 @@
|
||||
// Login.tsx
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { FirebaseAuthTypes } from "@react-native-firebase/auth";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
Keyboard,
|
||||
@ -7,27 +9,30 @@ import {
|
||||
TextInput,
|
||||
TouchableWithoutFeedback,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import { handleSignInWithPhoneNumber, confirmCode, onAuthStateChanged } from '../auth';
|
||||
import { FirebaseAuthTypes } from '@react-native-firebase/auth';
|
||||
import { useAuthHeader } from '../graphql/client';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import SignOutButton from '../component/buttons/sign-out';
|
||||
} from "react-native";
|
||||
import {
|
||||
confirmCode,
|
||||
handleSignInWithPhoneNumber,
|
||||
onAuthStateChanged,
|
||||
} from "../auth";
|
||||
import SignOutButton from "../component/buttons/sign-out";
|
||||
import { useAuthHeader } from "../graphql/client";
|
||||
|
||||
export default function Login() {
|
||||
const [phoneNumber, setPhoneNumber] = useState<string>('');
|
||||
const [code, setCode] = useState<string>('');
|
||||
const [phoneNumber, setPhoneNumber] = useState<string>("");
|
||||
const [code, setCode] = useState<string>("");
|
||||
const [user, setUser] = useState<FirebaseAuthTypes.User | null>(null);
|
||||
const [confirm, setConfirm] = useState<FirebaseAuthTypes.ConfirmationResult | null>(null);
|
||||
const { authHeader, setAuthHeader } = useAuthHeader()
|
||||
const [confirm, setConfirm] =
|
||||
useState<FirebaseAuthTypes.ConfirmationResult | null>(null);
|
||||
const { authHeader, setAuthHeader } = useAuthHeader();
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = onAuthStateChanged(async (user) => {
|
||||
setUser(user)
|
||||
setUser(user);
|
||||
if (user) {
|
||||
const token = await user.getIdToken()
|
||||
const token = await user.getIdToken();
|
||||
if (token) {
|
||||
await AsyncStorage.setItem('token', token);
|
||||
await AsyncStorage.setItem("token", token);
|
||||
setAuthHeader({ key: "Authorization", value: `Bearer ${token}` });
|
||||
}
|
||||
}
|
||||
@ -36,11 +41,9 @@ export default function Login() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
|
||||
<View style={{ alignItems: 'center' }}>
|
||||
<View style={{ alignItems: "center" }}>
|
||||
<TextInput
|
||||
style={{
|
||||
width: "50%",
|
||||
@ -74,10 +77,16 @@ export default function Login() {
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
title={!confirm ? 'Receive code' : 'Confirm code'}
|
||||
onPress={() => !confirm ? handleSignInWithPhoneNumber(phoneNumber).then(setConfirm) : confirm && confirmCode(confirm, code)}
|
||||
title={!confirm ? "Receive code" : "Confirm code"}
|
||||
onPress={() =>
|
||||
!confirm
|
||||
? handleSignInWithPhoneNumber(phoneNumber).then(setConfirm)
|
||||
: confirm && confirmCode(confirm, code)
|
||||
}
|
||||
/>
|
||||
<Text>{authHeader.key}: {authHeader.value}</Text>
|
||||
<Text>
|
||||
{authHeader.key}: {authHeader.value}
|
||||
</Text>
|
||||
{user && (
|
||||
<>
|
||||
<Text style={{ marginTop: 10 }}>
|
||||
|
Loading…
Reference in New Issue
Block a user