16 lines
493 B
TypeScript
16 lines
493 B
TypeScript
import { onAuthStateChanged, User } from "firebase/auth";
|
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
import { auth } from "./config";
|
|
|
|
export const monitorAuthState = (onUserChange: (user: User | null) => void) => {
|
|
onAuthStateChanged(auth, async (user) => {
|
|
if (user) {
|
|
await AsyncStorage.setItem("user", JSON.stringify(user));
|
|
onUserChange(user);
|
|
} else {
|
|
await AsyncStorage.removeItem("user");
|
|
onUserChange(null);
|
|
}
|
|
});
|
|
};
|