mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-07-18 17:25:41 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user