mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-04-22 03:07: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) {
|
export function TradeView({ tradeId, onBack }: TradeViewProps) {
|
||||||
const { sessionToken, user } = useAuth();
|
const { sessionToken, authUserId } = useAuth();
|
||||||
const { t, isRTL } = useTranslation();
|
const { t, isRTL } = useTranslation();
|
||||||
const { hapticImpact, hapticNotification } = useTelegram();
|
const { hapticImpact, hapticNotification } = useTelegram();
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ export function TradeView({ tradeId, onBack }: TradeViewProps) {
|
|||||||
const [showDispute, setShowDispute] = useState(false);
|
const [showDispute, setShowDispute] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const userId = user?.id;
|
// authUserId = auth.users UUID (matches trade.buyer_id / trade.seller_id)
|
||||||
const isBuyer = trade?.buyer_id === userId;
|
const isBuyer = trade?.buyer_id === authUserId;
|
||||||
const isSeller = trade?.seller_id === userId;
|
const isSeller = trade?.seller_id === authUserId;
|
||||||
|
|
||||||
const fetchTrade = useCallback(async () => {
|
const fetchTrade = useCallback(async () => {
|
||||||
if (!sessionToken || !tradeId) return;
|
if (!sessionToken || !tradeId) return;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type { User } from '@/hooks/useSupabase';
|
|||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
|
authUserId: string | null;
|
||||||
sessionToken: string | null;
|
sessionToken: string | null;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
@@ -49,6 +50,7 @@ function waitForInitData(maxAttempts = 25, intervalMs = 200): Promise<string | n
|
|||||||
|
|
||||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
|
const [authUserId, setAuthUserId] = useState<string | null>(null);
|
||||||
const [sessionToken, setSessionToken] = useState<string | null>(null);
|
const [sessionToken, setSessionToken] = useState<string | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [authError, setAuthError] = useState<string | null>(null);
|
const [authError, setAuthError] = useState<string | null>(null);
|
||||||
@@ -70,6 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const result = await signInWithTelegram(initData);
|
const result = await signInWithTelegram(initData);
|
||||||
if (result?.user) {
|
if (result?.user) {
|
||||||
setUser(result.user);
|
setUser(result.user);
|
||||||
|
setAuthUserId(result.auth_user_id || null);
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
} else {
|
} else {
|
||||||
setAuthError('No user returned from auth');
|
setAuthError('No user returned from auth');
|
||||||
@@ -98,6 +101,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
<AuthContext.Provider
|
<AuthContext.Provider
|
||||||
value={{
|
value={{
|
||||||
user,
|
user,
|
||||||
|
authUserId,
|
||||||
sessionToken,
|
sessionToken,
|
||||||
isLoading,
|
isLoading,
|
||||||
isAuthenticated: !!user,
|
isAuthenticated: !!user,
|
||||||
|
|||||||
Reference in New Issue
Block a user