some stuff
This commit is contained in:
parent
37004a1f6e
commit
f849780aac
@ -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,
|
user: FirebaseAuthTypes.User,
|
||||||
token: string,
|
token: string,
|
||||||
isLoggedIn: boolean,
|
isLoggedIn: boolean,
|
||||||
|
tokenType: "user_id" | "Authorization" = "Authorization",
|
||||||
) => {
|
) => {
|
||||||
setAuthHeader({ key: "Authorization", value: token });
|
setAuthHeader({ key: tokenType, value: token });
|
||||||
setContextUser(user);
|
setContextUser(user);
|
||||||
setIsLoggedIn(isLoggedIn);
|
setIsLoggedIn(isLoggedIn);
|
||||||
setIsLoading(false);
|
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();
|
||||||
|
@ -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 {
|
||||||
|
@ -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%",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user