Advertisement
Wonkiest29

page.tsx [part of code]

May 6th, 2025
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. useEffect(() => {
  2.     const checkAuthentication = async () => {
  3.       setAuthChecking(true);
  4.      
  5.       const isTelegramEnvironment =
  6.         typeof window !== 'undefined' &&
  7.         window.Telegram &&
  8.         window.Telegram.WebApp;
  9.      
  10.       const hasAuthCookie = getAuthTokenFromCookies() !== null;
  11.      
  12.       const isTelegramAuth = !!user && !telegramLoading && !telegramError;
  13.      
  14.       if (isTelegramEnvironment) {
  15.         console.log("Running inside Telegram Mini App environment");
  16.       } else {
  17.         console.log("Not running in Telegram Mini App environment");
  18.       }
  19.      
  20.       if (isTelegramAuth) {
  21.         console.log("Авторизация через Telegram успешна", {
  22.           userId: user?.id,
  23.           firstName: user?.firstName,
  24.           username: user?.username
  25.         });
  26.        
  27.         if (typeof window !== 'undefined') {
  28.           localStorage.setItem("telegramUser", JSON.stringify({
  29.             id: user.id,
  30.             firstName: user.firstName,
  31.             lastName: user.lastName,
  32.             username: user.username
  33.           }));
  34.         }
  35.       } else if (telegramError) {
  36.         console.error("Telegram auth error:", telegramError);
  37.       }
  38.      
  39.       if (hasAuthCookie) {
  40.         console.log("✅ logged in");
  41.       }
  42.      
  43.       const isAuth = hasAuthCookie || isTelegramAuth;
  44.       setIsAuthenticated(isAuth);
  45.      
  46.       if (isAuth) {
  47.         await fetchChats();
  48.       }
  49.      
  50.       setAuthChecking(false);
  51.     };
  52.    
  53.     checkAuthentication();
  54.   }, [telegramLoading, telegramError, user]);
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement