mirror of
https://github.com/pezkuwichain/pezkuwi-p2p-mobile.git
synced 2026-06-19 00:41:12 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user