fix: use auth.users UUID for trade role matching

telegram-auth now returns auth_user_id alongside public.users data.
TradeView uses authUserId (auth.users UUID) to match buyer_id/seller_id,
fixing missing action buttons (mark paid, confirm, cancel).
This commit is contained in:
2026-02-27 01:51:14 +03:00
parent 8c36b832b8
commit 556b850ec2
2 changed files with 8 additions and 4 deletions
+4 -4
View File
@@ -36,7 +36,7 @@ const STATUS_CONFIG: Record<string, { color: string; icon: typeof Clock }> = {
};
export function TradeView({ tradeId, onBack }: TradeViewProps) {
const { sessionToken, user } = useAuth();
const { sessionToken, authUserId } = useAuth();
const { t, isRTL } = useTranslation();
const { hapticImpact, hapticNotification } = useTelegram();
@@ -47,9 +47,9 @@ export function TradeView({ tradeId, onBack }: TradeViewProps) {
const [showDispute, setShowDispute] = useState(false);
const [error, setError] = useState('');
const userId = user?.id;
const isBuyer = trade?.buyer_id === userId;
const isSeller = trade?.seller_id === userId;
// authUserId = auth.users UUID (matches trade.buyer_id / trade.seller_id)
const isBuyer = trade?.buyer_id === authUserId;
const isSeller = trade?.seller_id === authUserId;
const fetchTrade = useCallback(async () => {
if (!sessionToken || !tradeId) return;
+4
View File
@@ -12,6 +12,7 @@ import type { User } from '@/hooks/useSupabase';
interface AuthContextType {
user: User | null;
authUserId: string | null;
sessionToken: string | null;
isLoading: boolean;
isAuthenticated: boolean;
@@ -49,6 +50,7 @@ function waitForInitData(maxAttempts = 25, intervalMs = 200): Promise<string | n
export function AuthProvider({ children }: { children: ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const [authUserId, setAuthUserId] = useState<string | null>(null);
const [sessionToken, setSessionToken] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [authError, setAuthError] = useState<string | null>(null);
@@ -70,6 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const result = await signInWithTelegram(initData);
if (result?.user) {
setUser(result.user);
setAuthUserId(result.auth_user_id || null);
setAuthError(null);
} else {
setAuthError('No user returned from auth');
@@ -98,6 +101,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
<AuthContext.Provider
value={{
user,
authUserId,
sessionToken,
isLoading,
isAuthenticated: !!user,