mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-04-21 23:37:55 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user