Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/context/AuthContext.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-refresh/only-export-components */
import { githubFetch, getRateLimitMessage } from "../utils/githubRateLimit";
import React, { createContext, useContext, useState, useEffect } from "react";
import React, { createContext, useContext, useState, useEffect, useRef } from "react";
import {
onAuthStateChanged,
getAdditionalUserInfo,
Expand Down Expand Up @@ -95,6 +95,18 @@ export const AuthProvider = ({ children }) => {
const [loading, setLoading] = useState(auth ? true : false);
const [isOnboarding, setIsOnboarding] = useState(false);
const [ghAccessToken, setGhAccessToken] = useState(null);
const uidRef = useRef(null);

// Cross-tab avatar sync: listen for avatar updates from other tabs
useEffect(() => {
const handleStorage = (e) => {
if (e.key?.startsWith('rh_avatar_') && e.newValue && e.key.replace('rh_avatar_', '') === uidRef.current) {
setUserData(prev => prev ? { ...prev, avatar: e.newValue } : prev);
}
};
window.addEventListener('storage', handleStorage);
return () => window.removeEventListener('storage', handleStorage);
}, []);

useEffect(() => {
if (!auth) {
Expand Down Expand Up @@ -169,6 +181,7 @@ export const AuthProvider = ({ children }) => {

if (currentUser) {
setUser(currentUser);
uidRef.current = currentUser.uid;

const userDocRef = doc(db, "users", currentUser.uid);

Expand Down Expand Up @@ -210,6 +223,7 @@ export const AuthProvider = ({ children }) => {
setUserData(null);
setIsOnboarding(false);
setLoading(false);
uidRef.current = null;
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/pages/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export const Profile = () => {
...updateData
}));
}
// Sync avatar across open tabs via localStorage
localStorage.setItem(`rh_avatar_${user.uid}`, editAvatar.trim());

setToasts((prev) => [...prev, { id: Date.now() + Math.random(), message: "Profile updated successfully!", type: "success" }]);
setIsEditModalOpen(false);
Expand Down