fix: use Telegram auth user ID instead of Supabase Auth

- Add setCurrentUserId/getCurrentUserId helpers for Telegram-based auth
- Update all p2p-fiat functions to use getCurrentUserId()
- AuthContext sets currentUserId on login/logout
- Fallback to supabase.auth.getUser() for web compatibility

This allows p2p-fiat functions to work with Telegram-only authentication
where users don't have a Supabase Auth session.
This commit is contained in:
2026-02-03 12:25:28 +03:00
parent 4074e7a884
commit c6b18b4f11
2 changed files with 51 additions and 18 deletions
+5
View File
@@ -1,5 +1,6 @@
import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from 'react';
import { supabase } from '@/lib/supabase';
import { setCurrentUserId } from '@/lib/p2p-fiat';
// Telegram WebApp types
declare global {
@@ -108,6 +109,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
setUser(data.user);
setCurrentUserId(data.user.id); // Set user ID for p2p-fiat functions
setTelegramUser(getTelegramUser());
// Store session token if provided
@@ -129,6 +131,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
// Logout
const logout = useCallback(() => {
setUser(null);
setCurrentUserId(null); // Clear user ID for p2p-fiat functions
localStorage.removeItem('p2p_session');
window.Telegram?.WebApp.HapticFeedback.impactOccurred('medium');
}, []);
@@ -189,6 +192,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
setUser(data.user);
setCurrentUserId(data.user.id); // Set user ID for p2p-fiat functions
// Store session token
if (data.session_token) {
@@ -221,6 +225,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
});
if (!error && data?.user) {
setUser(data.user);
setCurrentUserId(data.user.id); // Set user ID for p2p-fiat functions
setIsLoading(false);
return;
}