From 7a08cb8373b1645c4c504fb0824bf7a3792cd9d1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 25 Dec 2024 04:06:49 +0000 Subject: [PATCH] fix: use correct database instance and reference in AuthProvider Co-Authored-By: WeWrite --- app/providers/AuthProvider.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/providers/AuthProvider.js b/app/providers/AuthProvider.js index 82b4416..d2cc3b6 100644 --- a/app/providers/AuthProvider.js +++ b/app/providers/AuthProvider.js @@ -2,7 +2,7 @@ import { useEffect, useState, createContext, useContext } from "react"; import { auth, onAuthStateChanged } from "../firebase/auth"; -import { db } from "../firebase/rtdb"; +import database from "../firebase/rtdb"; export const AuthContext = createContext(); @@ -56,12 +56,16 @@ export const AuthProvider = ({ children }) => { unsubscribe = onAuthStateChanged(auth, async (authUser) => { try { if (authUser) { - const userSnapshot = await db.ref(`users/${authUser.uid}`).get(); + const userRef = database.ref(`users/${authUser.uid}`); + const userSnapshot = await userRef.get(); const userData = userSnapshot.val() || {}; let stripeCustomerId = userData.stripeCustomerId; if (!stripeCustomerId) { stripeCustomerId = await createStripeCustomer(authUser); + if (stripeCustomerId) { + await userRef.update({ stripeCustomerId }); + } } setUser({