some stuff
This commit is contained in:
parent
37004a1f6e
commit
f849780aac
@ -1,6 +1,12 @@
|
||||
import { DEV_USER_ID } from "@env";
|
||||
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 { useAuthHeader } from "../graphql/client";
|
||||
|
||||
@ -24,16 +30,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
|
||||
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,
|
||||
isLoggedIn: boolean,
|
||||
tokenType: "user_id" | "Authorization" = "Authorization",
|
||||
) => {
|
||||
setAuthHeader({ key: "Authorization", value: token });
|
||||
setAuthHeader({ key: tokenType, value: token });
|
||||
setContextUser(user);
|
||||
setIsLoggedIn(isLoggedIn);
|
||||
setIsLoading(false);
|
||||
};
|
||||
},
|
||||
[setAuthHeader],
|
||||
);
|
||||
|
||||
const authStateChangeCallback = async (user: FirebaseAuthTypes.User) => {
|
||||
if (user) {
|
||||
@ -61,13 +71,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
const setAuthAsync = async () => {
|
||||
if (DEV_USER_ID) {
|
||||
console.log("Setting fake authorization user to: ", DEV_USER_ID);
|
||||
setAuthHeader({ key: "user_id", value: DEV_USER_ID });
|
||||
setIsLoggedIn(true);
|
||||
setIsLoading(false);
|
||||
_completeAuthentication(null, DEV_USER_ID, true, "user_id");
|
||||
}
|
||||
};
|
||||
setAuthAsync();
|
||||
}, [setAuthHeader]);
|
||||
}, [_completeAuthentication]);
|
||||
|
||||
const logOut = async () => {
|
||||
await handleSignOut();
|
||||
|
@ -1,4 +1,3 @@
|
||||
// Login.tsx
|
||||
import { FirebaseAuthTypes } from "@react-native-firebase/auth";
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
|
@ -13,12 +13,8 @@ export default function ProfileScreen() {
|
||||
{user && (
|
||||
<>
|
||||
<View style={styles.userInfo}>
|
||||
<Text>
|
||||
Display name: {user?.displayName}
|
||||
</Text>
|
||||
<Text>
|
||||
Phone number: {user?.phoneNumber}
|
||||
</Text>
|
||||
<Text>Display name: {user?.displayName}</Text>
|
||||
<Text>Phone number: {user?.phoneNumber}</Text>
|
||||
</View>
|
||||
<View style={styles.signOutButton}>
|
||||
<SignOutButton />
|
||||
@ -40,6 +36,6 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
signOutButton: {
|
||||
paddingBottom: "5%",
|
||||
paddingHorizontal: "25%"
|
||||
paddingHorizontal: "25%",
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user