some stuff

This commit is contained in:
Loewy 2024-02-07 22:06:19 -08:00
parent 37004a1f6e
commit f849780aac
3 changed files with 26 additions and 23 deletions

View File

@ -1,6 +1,12 @@
import { DEV_USER_ID } from "@env"; import { DEV_USER_ID } from "@env";
import { FirebaseAuthTypes } from "@react-native-firebase/auth"; import { FirebaseAuthTypes } from "@react-native-firebase/auth";
import React, { createContext, useContext, useEffect, useState } from "react"; import React, {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from "react";
import { handleSignOut, onAuthStateChanged } from "../auth"; import { handleSignOut, onAuthStateChanged } from "../auth";
import { useAuthHeader } from "../graphql/client"; import { useAuthHeader } from "../graphql/client";
@ -24,16 +30,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false); const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(true); // this is for a LoadingContext (auth, app reloads, foreground etc) const [isLoading, setIsLoading] = useState<boolean>(true); // this is for a LoadingContext (auth, app reloads, foreground etc)
const _completeAuthentication = ( const _completeAuthentication = useCallback(
user: FirebaseAuthTypes.User, (
token: string, user: FirebaseAuthTypes.User,
isLoggedIn: boolean, token: string,
) => { isLoggedIn: boolean,
setAuthHeader({ key: "Authorization", value: token }); tokenType: "user_id" | "Authorization" = "Authorization",
setContextUser(user); ) => {
setIsLoggedIn(isLoggedIn); setAuthHeader({ key: tokenType, value: token });
setIsLoading(false); setContextUser(user);
}; setIsLoggedIn(isLoggedIn);
setIsLoading(false);
},
[setAuthHeader],
);
const authStateChangeCallback = async (user: FirebaseAuthTypes.User) => { const authStateChangeCallback = async (user: FirebaseAuthTypes.User) => {
if (user) { if (user) {
@ -61,13 +71,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
const setAuthAsync = async () => { const setAuthAsync = async () => {
if (DEV_USER_ID) { if (DEV_USER_ID) {
console.log("Setting fake authorization user to: ", DEV_USER_ID); console.log("Setting fake authorization user to: ", DEV_USER_ID);
setAuthHeader({ key: "user_id", value: DEV_USER_ID }); _completeAuthentication(null, DEV_USER_ID, true, "user_id");
setIsLoggedIn(true);
setIsLoading(false);
} }
}; };
setAuthAsync(); setAuthAsync();
}, [setAuthHeader]); }, [_completeAuthentication]);
const logOut = async () => { const logOut = async () => {
await handleSignOut(); await handleSignOut();

View File

@ -1,4 +1,3 @@
// Login.tsx
import { FirebaseAuthTypes } from "@react-native-firebase/auth"; import { FirebaseAuthTypes } from "@react-native-firebase/auth";
import React, { useState } from "react"; import React, { useState } from "react";
import { import {

View File

@ -13,12 +13,8 @@ export default function ProfileScreen() {
{user && ( {user && (
<> <>
<View style={styles.userInfo}> <View style={styles.userInfo}>
<Text> <Text>Display name: {user?.displayName}</Text>
Display name: {user?.displayName} <Text>Phone number: {user?.phoneNumber}</Text>
</Text>
<Text>
Phone number: {user?.phoneNumber}
</Text>
</View> </View>
<View style={styles.signOutButton}> <View style={styles.signOutButton}>
<SignOutButton /> <SignOutButton />
@ -40,6 +36,6 @@ const styles = StyleSheet.create({
}, },
signOutButton: { signOutButton: {
paddingBottom: "5%", paddingBottom: "5%",
paddingHorizontal: "25%" paddingHorizontal: "25%",
}, },
}); });