feat: add session token support for P2P cross-app auth

- AuthContext now stores and exposes sessionToken from telegram-auth
- App.tsx sends session_token instead of tg_id to P2P
- Enables secure cross-app authentication without from_miniapp method
This commit is contained in:
2026-02-06 04:34:49 +03:00
parent 0c1c440382
commit 3f8c8f4311
5 changed files with 59 additions and 10 deletions
+7
View File
@@ -4,6 +4,7 @@ import type { User } from '@/hooks/useSupabase';
interface AuthContextType {
user: User | null;
sessionToken: string | null;
isLoading: boolean;
isAuthenticated: boolean;
signIn: () => Promise<void>;
@@ -13,6 +14,7 @@ const AuthContext = createContext<AuthContextType | null>(null);
export function AuthProvider({ children }: { children: ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const [sessionToken, setSessionToken] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const signIn = async () => {
@@ -28,6 +30,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
if (result?.user) {
setUser(result.user);
}
// Store session token for P2P and other cross-app auth
if (result?.session_token) {
setSessionToken(result.session_token);
}
} catch (error) {
// Auth failed silently - user will see unauthenticated state
if (import.meta.env.DEV) {
@@ -47,6 +53,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
<AuthContext.Provider
value={{
user,
sessionToken,
isLoading,
isAuthenticated: !!user,
signIn,