Skip to content

Commit

Permalink
fix: use correct database instance and reference in AuthProvider
Browse files Browse the repository at this point in the history
Co-Authored-By: WeWrite <getwewrite@gmail.com>
  • Loading branch information
devin-ai-integration[bot] and getwewrite committed Dec 25, 2024
1 parent 769be44 commit 7a08cb8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/providers/AuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 7a08cb8

Please sign in to comment.