Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- useEffect(() => {
- const checkAuthentication = async () => {
- setAuthChecking(true);
- const isTelegramEnvironment =
- typeof window !== 'undefined' &&
- window.Telegram &&
- window.Telegram.WebApp;
- const hasAuthCookie = getAuthTokenFromCookies() !== null;
- const isTelegramAuth = !!user && !telegramLoading && !telegramError;
- if (isTelegramEnvironment) {
- console.log("Running inside Telegram Mini App environment");
- } else {
- console.log("Not running in Telegram Mini App environment");
- }
- if (isTelegramAuth) {
- console.log("Авторизация через Telegram успешна", {
- userId: user?.id,
- firstName: user?.firstName,
- username: user?.username
- });
- if (typeof window !== 'undefined') {
- localStorage.setItem("telegramUser", JSON.stringify({
- id: user.id,
- firstName: user.firstName,
- lastName: user.lastName,
- username: user.username
- }));
- }
- } else if (telegramError) {
- console.error("Telegram auth error:", telegramError);
- }
- if (hasAuthCookie) {
- console.log("✅ logged in");
- }
- const isAuth = hasAuthCookie || isTelegramAuth;
- setIsAuthenticated(isAuth);
- if (isAuth) {
- await fetchChats();
- }
- setAuthChecking(false);
- };
- checkAuthentication();
- }, [telegramLoading, telegramError, user]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement