feat: add Russian translation and readme #428
@@ -6,14 +6,11 @@ on:
|
|||||||
version:
|
version:
|
||||||
description: "Version to build (e.g., 1.8.0)"
|
description: "Version to build (e.g., 1.8.0)"
|
||||||
required: true
|
required: true
|
||||||
build_type:
|
production:
|
||||||
description: "Build type"
|
description: "Is this a production build?"
|
||||||
required: true
|
required: true
|
||||||
default: "Development"
|
default: false
|
||||||
type: choice
|
type: boolean
|
||||||
options:
|
|
||||||
- Development
|
|
||||||
- Production
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -36,25 +33,29 @@ jobs:
|
|||||||
id: tags
|
id: tags
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ github.event.inputs.version }}
|
VERSION=${{ github.event.inputs.version }}
|
||||||
BUILD_TYPE=${{ github.event.inputs.build_type }}
|
PROD=${{ github.event.inputs.production }}
|
||||||
|
|
||||||
TAGS=()
|
TAGS=()
|
||||||
ALL_TAGS=()
|
ALL_TAGS=()
|
||||||
|
|
||||||
if [ "$BUILD_TYPE" = "Production" ]; then
|
if [ "$PROD" = "true" ]; then
|
||||||
|
# Production build → push release + latest to both GHCR and Docker Hub
|
||||||
TAGS+=("release-$VERSION" "latest")
|
TAGS+=("release-$VERSION" "latest")
|
||||||
for tag in "${TAGS[@]}"; do
|
for tag in "${TAGS[@]}"; do
|
||||||
ALL_TAGS+=("ghcr.io/lukegus/termix:$tag")
|
ALL_TAGS+=("ghcr.io/lukegus/termix:$tag")
|
||||||
ALL_TAGS+=("docker.io/bugattiguy527/termix:$tag")
|
ALL_TAGS+=("docker.io/bugattiguy527/termix:$tag")
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
# Dev build → push only dev-x.x.x to GHCR
|
||||||
TAGS+=("dev-$VERSION")
|
TAGS+=("dev-$VERSION")
|
||||||
for tag in "${TAGS[@]}"; do
|
for tag in "${TAGS[@]}"; do
|
||||||
ALL_TAGS+=("ghcr.io/lukegus/termix:$tag")
|
ALL_TAGS+=("ghcr.io/lukegus/termix:$tag")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "ALL_TAGS=$(printf '%s\n' "${ALL_TAGS[@]}")" >> $GITHUB_ENV
|
echo "ALL_TAGS=${ALL_TAGS[*]}" >> $GITHUB_ENV
|
||||||
|
echo "All tags to build:"
|
||||||
|
printf '%s\n' "${ALL_TAGS[@]}"
|
||||||
|
|
||||||
- name: Login to GHCR
|
- name: Login to GHCR
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
@@ -64,7 +65,7 @@ jobs:
|
|||||||
password: ${{ secrets.GHCR_TOKEN }}
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
|
|
||||||
- name: Login to Docker Hub (prod only)
|
- name: Login to Docker Hub (prod only)
|
||||||
if: ${{ github.event.inputs.build_type == 'Production' }}
|
if: ${{ github.event.inputs.production == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: bugattiguy527
|
username: bugattiguy527
|
||||||
|
|||||||
+447
-106
File diff suppressed because it is too large
Load Diff
+137
@@ -0,0 +1,137 @@
|
|||||||
|
# Статистика репозитория
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://flagcdn.com/us.svg" alt="English" width="24" height="16"> English |
|
||||||
|
<a href="README-CN.md"><img src="https://flagcdn.com/cn.svg" alt="中文" width="24" height="16"> 中文</a> |
|
||||||
|
<a href="README-RU.md"><img src="https://flagcdn.com/ru.svg" alt="Русский" width="24" height="16"> Русский</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
<a href="https://discord.gg/jVQGdvHDrf"><img alt="Discord" src="https://img.shields.io/discord/1347374268253470720"></a>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./repo-images/RepoOfTheDay.png" alt="Достижение дня" style="width: 300px; height: auto;">
|
||||||
|
<br>
|
||||||
|
<small style="color: #666;">Достигнуто 1 сентября 2025 года</small>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
#### Лучшие технологии
|
||||||
|
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/Termix-SSH/Termix">
|
||||||
|
<img alt="Баннер Termix" src=./repo-images/HeaderImage.png style="width: auto; height: auto;"> </a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Если хотите, вы можете поддержать проект здесь!\
|
||||||
|
[](https://github.com/sponsors/LukeGus)
|
||||||
|
|
||||||
|
# Обзор
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/Termix-SSH/Termix">
|
||||||
|
<img alt="Баннер Termix" src=./public/icon.svg style="width: 250px; height: 250px;"> </a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Termix — это открытая, бесплатная и самохостинговая универсальная платформа для управления серверами. Она предоставляет веб-решение
|
||||||
|
для управления вашими серверами и инфраструктурой через единый интуитивно понятный интерфейс. Termix предлагает доступ к SSH-терминалу,
|
||||||
|
возможности SSH-туннелирования и удаленное управление файлами, а в будущем появится еще больше инструментов.
|
||||||
|
|
||||||
|
# Особенности
|
||||||
|
|
||||||
|
- **Доступ к SSH-терминалу** — полнофункциональный терминал с поддержкой разделения экрана (до 4 панелей) и системой вкладок
|
||||||
|
- **Управление SSH-туннелями** — создание и управление SSH-туннелями с автоматической переподключением и мониторингом работоспособности
|
||||||
|
- **Удаленный файловый менеджер** — управление файлами непосредственно на удаленных серверах с поддержкой просмотра и редактирования кода, изображений, аудио и видео. Беспроблемная загрузка, скачивание, переименование, удаление и перемещение файлов.
|
||||||
|
- **Менеджер хостов SSH** — сохраняйте, систематизируйте и управляйте своими SSH-соединениями с помощью тегов и папок, а также легко сохраняйте повторно используемую информацию для входа в систему, имея возможность автоматизировать развертывание SSH-ключей
|
||||||
|
- **Статистика сервера** — просмотр использования ЦП, памяти и жесткого диска на любом SSH-сервере
|
||||||
|
- **Аутентификация пользователей** - Безопасное управление пользователями с помощью элементов управления администратора и поддержки OIDC и 2FA (TOTP).
|
||||||
|
- **Шифрование базы данных** - Файлы базы данных SQLite шифруются в режиме ожидания с помощью автоматического шифрования/дешифрования.
|
||||||
|
- **Экспорт/импорт данных** - Экспорт и импорт SSH-хостов, учетных данных и данных файлового менеджера с инкрементной синхронизацией.
|
||||||
|
- **Автоматическая настройка SSL** - Встроенная генерация и управление SSL-сертификатами с перенаправлением HTTPS.
|
||||||
|
- **Современный интерфейс** - Чистый интерфейс, удобный для настольных компьютеров и мобильных устройств, созданный с помощью React, Tailwind CSS и Shadcn
|
||||||
|
- **Языки** - Встроенная поддержка английского, китайского и немецкого языков
|
||||||
|
- **Поддержка платформ** - Доступно в виде веб-приложения, настольного приложения (Windows и Linux) и специального мобильного приложения для iOS и Android. Планируется поддержка macOS и iPadOS.
|
||||||
|
|
||||||
|
# Планируемые функции
|
||||||
|
|
||||||
|
Смотрите [Projects](https://github.com/orgs/Termix-SSH/projects/2) для ознакомления со всеми запланированными функциями. Если вы хотите внести свой вклад смотрите [Contributing](https://github.com/Termix-SSH/Termix/blob/main/CONTRIBUTING.md).
|
||||||
|
|
||||||
|
# Установка
|
||||||
|
|
||||||
|
Поддерживаемые устройства:
|
||||||
|
|
||||||
|
- Веб-сайт (любой современный браузер, такой как Google, Safari и Firefox)
|
||||||
|
- Windows (приложение)
|
||||||
|
- Linux (приложение)
|
||||||
|
- iOS (приложение)
|
||||||
|
- Android (приложение)
|
||||||
|
- iPadOS и macOS находятся в стадии разработки
|
||||||
|
|
||||||
|
Посетите Termix [Docs](https://docs.termix.site/install) для получения дополнительной информации об установке Termix на всех платформах. В противном случае,
|
||||||
|
просмотрите пример файла Docker Compose здесь:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
termix:
|
||||||
|
image: ghcr.io/lukegus/termix:latest
|
||||||
|
container_name: termix
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- '8080:8080'
|
||||||
|
volumes:
|
||||||
|
- termix-data:/app/data
|
||||||
|
environment:
|
||||||
|
PORT: '8080'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
termix-data:
|
||||||
|
driver: local
|
||||||
|
```
|
||||||
|
|
||||||
|
# Поддержка
|
||||||
|
|
||||||
|
Если вам нужна помощь или вы хотите запросить функцию в Termix, посетите [Issues](https://github.com/Termix-SSH/Support/issues), войдите в систему и нажмите `New Issue`.
|
||||||
|
Пожалуйста, опишите свою проблему как можно подробнее, желательно на английском языке. Вы также можете присоединиться к [Discord](https://discord.gg/jVQGdvHDrf) серверу и посетите канал
|
||||||
|
службы поддержки, однако время отклика может быть более длительным.
|
||||||
|
|
||||||
|
# Внешний вид
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./repo-images/Image 1.png" width="400" alt="Termix Demo 1"/>
|
||||||
|
<img src="./repo-images/Image 2.png" width="400" alt="Termix Demo 2"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./repo-images/Image 3.png" width="400" alt="Termix Demo 3"/>
|
||||||
|
<img src="./repo-images/Image 4.png" width="400" alt="Termix Demo 4"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./repo-images/Image 5.png" width="400" alt="Termix Demo 5"/>
|
||||||
|
<img src="./repo-images/Image 6.png" width="400" alt="Termix Demo 6"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./repo-images/Image 7.png" width="400" alt="Termix Demo 7"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<video src="https://github.com/user-attachments/assets/88936e0d-2399-4122-8eee-c255c25da48c" width="800" controls>
|
||||||
|
Ваш браузер не поддерживает тег видео.
|
||||||
|
</video>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# Лицензия
|
||||||
|
|
||||||
|
Распространяется по лицензии Apache версии 2.0. Дополнительную информацию смотрите в файле LICENSE.
|
||||||
@@ -578,19 +578,6 @@ class AuthManager {
|
|||||||
sessionId,
|
sessionId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
await db.delete(sessions).where(eq(sessions.userId, userId));
|
|
||||||
} catch (error) {
|
|
||||||
databaseLogger.error(
|
|
||||||
"Failed to delete user sessions on logout",
|
|
||||||
error,
|
|
||||||
{
|
|
||||||
operation: "sessions_delete_logout_failed",
|
|
||||||
userId,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -6,12 +6,13 @@ import enTranslation from "../locales/en/translation.json";
|
|||||||
import zhTranslation from "../locales/zh/translation.json";
|
import zhTranslation from "../locales/zh/translation.json";
|
||||||
import deTranslation from "../locales/de/translation.json";
|
import deTranslation from "../locales/de/translation.json";
|
||||||
import ptbrTranslation from "../locales/pt-BR/translation.json";
|
import ptbrTranslation from "../locales/pt-BR/translation.json";
|
||||||
|
import ruTranslation from "../locales/ru/translation.json";
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
.use(initReactI18next)
|
.use(initReactI18next)
|
||||||
.init({
|
.init({
|
||||||
supportedLngs: ["en", "zh", "de", "ptbr"],
|
supportedLngs: ["en", "zh", "de", "ptbr", "ru"],
|
||||||
fallbackLng: "en",
|
fallbackLng: "en",
|
||||||
debug: false,
|
debug: false,
|
||||||
|
|
||||||
@@ -36,6 +37,9 @@ i18n
|
|||||||
ptbr: {
|
ptbr: {
|
||||||
translation: ptbrTranslation,
|
translation: ptbrTranslation,
|
||||||
},
|
},
|
||||||
|
ru: {
|
||||||
|
translation: ruTranslation,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
interpolation: {
|
interpolation: {
|
||||||
|
|||||||
@@ -1252,6 +1252,7 @@
|
|||||||
"enterCode": "Enter verification code",
|
"enterCode": "Enter verification code",
|
||||||
"backupCode": "Or use backup code",
|
"backupCode": "Or use backup code",
|
||||||
"verifyCode": "Verify Code",
|
"verifyCode": "Verify Code",
|
||||||
|
"redirectingToApp": "Redirecting to app...",
|
||||||
"enableTwoFactor": "Enable Two-Factor Authentication",
|
"enableTwoFactor": "Enable Two-Factor Authentication",
|
||||||
"disableTwoFactor": "Disable Two-Factor Authentication",
|
"disableTwoFactor": "Disable Two-Factor Authentication",
|
||||||
"scanQRCode": "Scan this QR code with your authenticator app",
|
"scanQRCode": "Scan this QR code with your authenticator app",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect, useCallback } from "react";
|
||||||
import { LeftSidebar } from "@/ui/desktop/navigation/LeftSidebar.tsx";
|
import { LeftSidebar } from "@/ui/desktop/navigation/LeftSidebar.tsx";
|
||||||
import { Dashboard } from "@/ui/desktop/apps/dashboard/Dashboard.tsx";
|
import { Dashboard } from "@/ui/desktop/apps/dashboard/Dashboard.tsx";
|
||||||
import { AppView } from "@/ui/desktop/navigation/AppView.tsx";
|
import { AppView } from "@/ui/desktop/navigation/AppView.tsx";
|
||||||
@@ -68,7 +68,8 @@ function AppContent() {
|
|||||||
|
|
||||||
const handleSelectView = () => {};
|
const handleSelectView = () => {};
|
||||||
|
|
||||||
const handleAuthSuccess = (authData: {
|
const handleAuthSuccess = useCallback(
|
||||||
|
(authData: {
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
username: string | null;
|
username: string | null;
|
||||||
userId: string | null;
|
userId: string | null;
|
||||||
@@ -76,7 +77,9 @@ function AppContent() {
|
|||||||
setIsAuthenticated(true);
|
setIsAuthenticated(true);
|
||||||
setIsAdmin(authData.isAdmin);
|
setIsAdmin(authData.isAdmin);
|
||||||
setUsername(authData.username);
|
setUsername(authData.username);
|
||||||
};
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const currentTabData = tabs.find((tab) => tab.id === currentTab);
|
const currentTabData = tabs.find((tab) => tab.id === currentTab);
|
||||||
const showTerminalView =
|
const showTerminalView =
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ import {
|
|||||||
getUserInfo,
|
getUserInfo,
|
||||||
getCookie,
|
getCookie,
|
||||||
isElectron,
|
isElectron,
|
||||||
|
getSessions,
|
||||||
|
revokeSession,
|
||||||
|
revokeAllUserSessions,
|
||||||
} from "@/ui/main-axios.ts";
|
} from "@/ui/main-axios.ts";
|
||||||
|
|
||||||
interface AdminSettingsProps {
|
interface AdminSettingsProps {
|
||||||
@@ -126,6 +129,7 @@ export function AdminSettings({
|
|||||||
expiresAt: string;
|
expiresAt: string;
|
||||||
lastActiveAt: string;
|
lastActiveAt: string;
|
||||||
jwtToken: string;
|
jwtToken: string;
|
||||||
|
isRevoked?: boolean;
|
||||||
}>
|
}>
|
||||||
>([]);
|
>([]);
|
||||||
const [sessionsLoading, setSessionsLoading] = React.useState(false);
|
const [sessionsLoading, setSessionsLoading] = React.useState(false);
|
||||||
@@ -565,35 +569,8 @@ export function AdminSettings({
|
|||||||
|
|
||||||
setSessionsLoading(true);
|
setSessionsLoading(true);
|
||||||
try {
|
try {
|
||||||
const isDev =
|
const data = await getSessions();
|
||||||
!isElectron() &&
|
|
||||||
process.env.NODE_ENV === "development" &&
|
|
||||||
(window.location.port === "3000" ||
|
|
||||||
window.location.port === "5173" ||
|
|
||||||
window.location.port === "" ||
|
|
||||||
window.location.hostname === "localhost" ||
|
|
||||||
window.location.hostname === "127.0.0.1");
|
|
||||||
|
|
||||||
const apiUrl = isElectron()
|
|
||||||
? `${(window as { configuredServerUrl?: string }).configuredServerUrl}/users/sessions`
|
|
||||||
: isDev
|
|
||||||
? `http://localhost:30001/users/sessions`
|
|
||||||
: `/users/sessions`;
|
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
|
||||||
method: "GET",
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${getCookie("jwt")}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
setSessions(data.sessions || []);
|
setSessions(data.sessions || []);
|
||||||
} else {
|
|
||||||
toast.error(t("admin.failedToFetchSessions"));
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!err?.message?.includes("No server configured")) {
|
if (!err?.message?.includes("No server configured")) {
|
||||||
toast.error(t("admin.failedToFetchSessions"));
|
toast.error(t("admin.failedToFetchSessions"));
|
||||||
@@ -612,30 +589,7 @@ export function AdminSettings({
|
|||||||
t("admin.confirmRevokeSession"),
|
t("admin.confirmRevokeSession"),
|
||||||
async () => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
const isDev =
|
await revokeSession(sessionId);
|
||||||
!isElectron() &&
|
|
||||||
process.env.NODE_ENV === "development" &&
|
|
||||||
(window.location.port === "3000" ||
|
|
||||||
window.location.port === "5173" ||
|
|
||||||
window.location.port === "" ||
|
|
||||||
window.location.hostname === "localhost" ||
|
|
||||||
window.location.hostname === "127.0.0.1");
|
|
||||||
|
|
||||||
const apiUrl = isElectron()
|
|
||||||
? `${(window as { configuredServerUrl?: string }).configuredServerUrl}/users/sessions/${sessionId}`
|
|
||||||
: isDev
|
|
||||||
? `http://localhost:30001/users/sessions/${sessionId}`
|
|
||||||
: `/users/sessions/${sessionId}`;
|
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
|
||||||
method: "DELETE",
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${getCookie("jwt")}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
toast.success(t("admin.sessionRevokedSuccessfully"));
|
toast.success(t("admin.sessionRevokedSuccessfully"));
|
||||||
|
|
||||||
if (isCurrentSession) {
|
if (isCurrentSession) {
|
||||||
@@ -645,9 +599,6 @@ export function AdminSettings({
|
|||||||
} else {
|
} else {
|
||||||
fetchSessions();
|
fetchSessions();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
toast.error(t("admin.failedToRevokeSession"));
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
toast.error(t("admin.failedToRevokeSession"));
|
toast.error(t("admin.failedToRevokeSession"));
|
||||||
}
|
}
|
||||||
@@ -663,39 +614,8 @@ export function AdminSettings({
|
|||||||
t("admin.confirmRevokeAllSessions"),
|
t("admin.confirmRevokeAllSessions"),
|
||||||
async () => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
const isDev =
|
const data = await revokeAllUserSessions(userId);
|
||||||
!isElectron() &&
|
toast.success(data.message || t("admin.sessionsRevokedSuccessfully"));
|
||||||
process.env.NODE_ENV === "development" &&
|
|
||||||
(window.location.port === "3000" ||
|
|
||||||
window.location.port === "5173" ||
|
|
||||||
window.location.port === "" ||
|
|
||||||
window.location.hostname === "localhost" ||
|
|
||||||
window.location.hostname === "127.0.0.1");
|
|
||||||
|
|
||||||
const apiUrl = isElectron()
|
|
||||||
? `${(window as { configuredServerUrl?: string }).configuredServerUrl}/users/sessions/revoke-all`
|
|
||||||
: isDev
|
|
||||||
? `http://localhost:30001/users/sessions/revoke-all`
|
|
||||||
: `/users/sessions/revoke-all`;
|
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${getCookie("jwt")}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
targetUserId: userId,
|
|
||||||
exceptCurrent: false,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
toast.success(
|
|
||||||
data.message || t("admin.sessionsRevokedSuccessfully"),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isCurrentUser) {
|
if (isCurrentUser) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -704,9 +624,6 @@ export function AdminSettings({
|
|||||||
} else {
|
} else {
|
||||||
fetchSessions();
|
fetchSessions();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
toast.error(t("admin.failedToRevokeSessions"));
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
toast.error(t("admin.failedToRevokeSessions"));
|
toast.error(t("admin.failedToRevokeSessions"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect, useCallback } from "react";
|
||||||
import { cn } from "@/lib/utils.ts";
|
import { cn } from "@/lib/utils.ts";
|
||||||
import { Button } from "@/components/ui/button.tsx";
|
import { Button } from "@/components/ui/button.tsx";
|
||||||
import { Input } from "@/components/ui/input.tsx";
|
import { Input } from "@/components/ui/input.tsx";
|
||||||
@@ -105,6 +105,33 @@ export function Auth({
|
|||||||
const [totpLoading, setTotpLoading] = useState(false);
|
const [totpLoading, setTotpLoading] = useState(false);
|
||||||
const [webviewAuthSuccess, setWebviewAuthSuccess] = useState(false);
|
const [webviewAuthSuccess, setWebviewAuthSuccess] = useState(false);
|
||||||
|
|
||||||
|
const handleElectronAuthSuccess = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const meRes = await getUserInfo();
|
||||||
|
setInternalLoggedIn(true);
|
||||||
|
setLoggedIn(true);
|
||||||
|
setIsAdmin(!!meRes.is_admin);
|
||||||
|
setUsername(meRes.username || null);
|
||||||
|
setUserId(meRes.userId || null);
|
||||||
|
onAuthSuccess({
|
||||||
|
isAdmin: !!meRes.is_admin,
|
||||||
|
username: meRes.username || null,
|
||||||
|
userId: meRes.userId || null,
|
||||||
|
});
|
||||||
|
toast.success(t("messages.loginSuccess"));
|
||||||
|
} catch (err) {
|
||||||
|
toast.error(t("errors.failedUserInfo"));
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
onAuthSuccess,
|
||||||
|
setLoggedIn,
|
||||||
|
setIsAdmin,
|
||||||
|
setUsername,
|
||||||
|
setUserId,
|
||||||
|
t,
|
||||||
|
setInternalLoggedIn,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInternalLoggedIn(loggedIn);
|
setInternalLoggedIn(loggedIn);
|
||||||
}, [loggedIn]);
|
}, [loggedIn]);
|
||||||
@@ -243,6 +270,7 @@ export function Auth({
|
|||||||
"*",
|
"*",
|
||||||
);
|
);
|
||||||
setWebviewAuthSuccess(true);
|
setWebviewAuthSuccess(true);
|
||||||
|
setTimeout(() => window.location.reload(), 100);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -419,6 +447,7 @@ export function Auth({
|
|||||||
"*",
|
"*",
|
||||||
);
|
);
|
||||||
setWebviewAuthSuccess(true);
|
setWebviewAuthSuccess(true);
|
||||||
|
setTimeout(() => window.location.reload(), 100);
|
||||||
setTotpLoading(false);
|
setTotpLoading(false);
|
||||||
return;
|
return;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -526,6 +555,7 @@ export function Auth({
|
|||||||
"*",
|
"*",
|
||||||
);
|
);
|
||||||
setWebviewAuthSuccess(true);
|
setWebviewAuthSuccess(true);
|
||||||
|
setTimeout(() => window.location.reload(), 100);
|
||||||
setOidcLoading(false);
|
setOidcLoading(false);
|
||||||
return;
|
return;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -688,24 +718,7 @@ export function Auth({
|
|||||||
<div className="w-full max-w-4xl h-[90vh]">
|
<div className="w-full max-w-4xl h-[90vh]">
|
||||||
<ElectronLoginForm
|
<ElectronLoginForm
|
||||||
serverUrl={currentServerUrl}
|
serverUrl={currentServerUrl}
|
||||||
onAuthSuccess={async () => {
|
onAuthSuccess={handleElectronAuthSuccess}
|
||||||
try {
|
|
||||||
const meRes = await getUserInfo();
|
|
||||||
setInternalLoggedIn(true);
|
|
||||||
setLoggedIn(true);
|
|
||||||
setIsAdmin(!!meRes.is_admin);
|
|
||||||
setUsername(meRes.username || null);
|
|
||||||
setUserId(meRes.userId || null);
|
|
||||||
onAuthSuccess({
|
|
||||||
isAdmin: !!meRes.is_admin,
|
|
||||||
username: meRes.username || null,
|
|
||||||
userId: meRes.userId || null,
|
|
||||||
});
|
|
||||||
toast.success(t("messages.loginSuccess"));
|
|
||||||
} catch (err) {
|
|
||||||
toast.error(t("errors.failedUserInfo"));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onChangeServer={() => {
|
onChangeServer={() => {
|
||||||
setShowServerConfig(true);
|
setShowServerConfig(true);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -3,23 +3,7 @@ import { Button } from "@/components/ui/button.tsx";
|
|||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert.tsx";
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert.tsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { AlertCircle, Loader2, ArrowLeft, RefreshCw } from "lucide-react";
|
import { AlertCircle, Loader2, ArrowLeft, RefreshCw } from "lucide-react";
|
||||||
import { getCookie, getUserInfo } from "@/ui/main-axios.ts";
|
import { getCookie } from "@/ui/main-axios.ts";
|
||||||
|
|
||||||
declare global {
|
|
||||||
namespace JSX {
|
|
||||||
interface IntrinsicElements {
|
|
||||||
webview: React.DetailedHTMLProps<
|
|
||||||
React.HTMLAttributes<HTMLElement>,
|
|
||||||
HTMLElement
|
|
||||||
> & {
|
|
||||||
src?: string;
|
|
||||||
partition?: string;
|
|
||||||
allowpopups?: string;
|
|
||||||
ref?: React.Ref<any>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ElectronLoginFormProps {
|
interface ElectronLoginFormProps {
|
||||||
serverUrl: string;
|
serverUrl: string;
|
||||||
@@ -36,12 +20,10 @@ export function ElectronLoginForm({
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
||||||
const webviewRef = useRef<any>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
const hasAuthenticatedRef = useRef(false);
|
const hasAuthenticatedRef = useRef(false);
|
||||||
const [currentUrl, setCurrentUrl] = useState(serverUrl);
|
const [currentUrl, setCurrentUrl] = useState(serverUrl);
|
||||||
const hasLoadedOnce = useRef(false);
|
const hasLoadedOnce = useRef(false);
|
||||||
const urlCheckInterval = useRef<NodeJS.Timeout | null>(null);
|
|
||||||
const loadTimeout = useRef<NodeJS.Timeout | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleMessage = async (event: MessageEvent) => {
|
const handleMessage = async (event: MessageEvent) => {
|
||||||
@@ -71,32 +53,11 @@ export function ElectronLoginForm({
|
|||||||
throw new Error("Failed to save JWT to localStorage");
|
throw new Error("Failed to save JWT to localStorage");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
await getUserInfo();
|
|
||||||
} catch (verifyErr) {
|
|
||||||
localStorage.removeItem("jwt");
|
|
||||||
const errorMsg =
|
|
||||||
verifyErr instanceof Error
|
|
||||||
? verifyErr.message
|
|
||||||
: "Failed to verify authentication";
|
|
||||||
console.error("Authentication verification failed:", verifyErr);
|
|
||||||
throw new Error(
|
|
||||||
errorMsg.includes("registration") ||
|
|
||||||
errorMsg.includes("allowed")
|
|
||||||
? "Authentication failed. Please check your server connection and try again."
|
|
||||||
: errorMsg,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
onAuthSuccess();
|
onAuthSuccess();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage =
|
setError(t("errors.authTokenSaveFailed"));
|
||||||
err instanceof Error
|
|
||||||
? err.message
|
|
||||||
: t("errors.authTokenSaveFailed");
|
|
||||||
setError(errorMessage);
|
|
||||||
setIsAuthenticating(false);
|
setIsAuthenticating(false);
|
||||||
hasAuthenticatedRef.current = false;
|
hasAuthenticatedRef.current = false;
|
||||||
}
|
}
|
||||||
@@ -113,66 +74,25 @@ export function ElectronLoginForm({
|
|||||||
}, [serverUrl, isAuthenticating, onAuthSuccess, t]);
|
}, [serverUrl, isAuthenticating, onAuthSuccess, t]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkWebviewUrl = () => {
|
const iframe = iframeRef.current;
|
||||||
const webview = webviewRef.current;
|
if (!iframe) return;
|
||||||
if (!webview) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const webviewUrl = webview.getURL();
|
|
||||||
if (webviewUrl && webviewUrl !== currentUrl) {
|
|
||||||
setCurrentUrl(webviewUrl);
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
urlCheckInterval.current = setInterval(checkWebviewUrl, 500);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (urlCheckInterval.current) {
|
|
||||||
clearInterval(urlCheckInterval.current);
|
|
||||||
urlCheckInterval.current = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [currentUrl]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const webview = webviewRef.current;
|
|
||||||
if (!webview) return;
|
|
||||||
|
|
||||||
loadTimeout.current = setTimeout(() => {
|
|
||||||
if (!hasLoadedOnce.current && loading) {
|
|
||||||
setLoading(false);
|
|
||||||
setError(
|
|
||||||
"Unable to connect to server. Please check the server URL and try again.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, 15000);
|
|
||||||
|
|
||||||
const handleLoad = () => {
|
const handleLoad = () => {
|
||||||
if (loadTimeout.current) {
|
|
||||||
clearTimeout(loadTimeout.current);
|
|
||||||
loadTimeout.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
hasLoadedOnce.current = true;
|
hasLoadedOnce.current = true;
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const webviewUrl = webview.getURL();
|
if (iframe.contentWindow) {
|
||||||
setCurrentUrl(webviewUrl || serverUrl);
|
setCurrentUrl(iframe.contentWindow.location.href);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setCurrentUrl(serverUrl);
|
setCurrentUrl(serverUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const injectedScript = `
|
const injectedScript = `
|
||||||
(function() {
|
(function() {
|
||||||
window.IS_ELECTRON = true;
|
|
||||||
window.IS_ELECTRON_WEBVIEW = true;
|
|
||||||
if (typeof window.electronAPI === 'undefined') {
|
|
||||||
window.electronAPI = { isElectron: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
let hasNotified = false;
|
let hasNotified = false;
|
||||||
|
|
||||||
function postJWTToParent(token, source) {
|
function postJWTToParent(token, source) {
|
||||||
@@ -193,36 +113,6 @@ export function ElectronLoginForm({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAuthData() {
|
|
||||||
try {
|
|
||||||
localStorage.removeItem('jwt');
|
|
||||||
sessionStorage.removeItem('jwt');
|
|
||||||
|
|
||||||
const cookies = document.cookie.split(';');
|
|
||||||
for (let i = 0; i < cookies.length; i++) {
|
|
||||||
const cookie = cookies[i];
|
|
||||||
const eqPos = cookie.indexOf('=');
|
|
||||||
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();
|
|
||||||
if (name === 'jwt') {
|
|
||||||
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
|
|
||||||
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=' + window.location.hostname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('message', function(event) {
|
|
||||||
try {
|
|
||||||
if (event.data && typeof event.data === 'object') {
|
|
||||||
if (event.data.type === 'CLEAR_AUTH_DATA') {
|
|
||||||
clearAuthData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function checkAuth() {
|
function checkAuth() {
|
||||||
try {
|
try {
|
||||||
const localToken = localStorage.getItem('jwt');
|
const localToken = localStorage.getItem('jwt');
|
||||||
@@ -290,10 +180,18 @@ export function ElectronLoginForm({
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
webview.executeJavaScript(injectedScript);
|
if (iframe.contentWindow) {
|
||||||
} catch (err) {
|
try {
|
||||||
console.error("Failed to inject authentication script:", err);
|
iframe.contentWindow.eval(injectedScript);
|
||||||
|
} catch (evalError) {
|
||||||
|
iframe.contentWindow.postMessage(
|
||||||
|
{ type: "INJECT_SCRIPT", script: injectedScript },
|
||||||
|
"*",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
} catch (err) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleError = () => {
|
const handleError = () => {
|
||||||
@@ -303,27 +201,18 @@ export function ElectronLoginForm({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
webview.addEventListener("did-finish-load", handleLoad);
|
iframe.addEventListener("load", handleLoad);
|
||||||
webview.addEventListener("did-fail-load", handleError);
|
iframe.addEventListener("error", handleError);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
webview.removeEventListener("did-finish-load", handleLoad);
|
iframe.removeEventListener("load", handleLoad);
|
||||||
webview.removeEventListener("did-fail-load", handleError);
|
iframe.removeEventListener("error", handleError);
|
||||||
if (loadTimeout.current) {
|
|
||||||
clearTimeout(loadTimeout.current);
|
|
||||||
loadTimeout.current = null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, [t, loading, serverUrl]);
|
}, [t]);
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
if (webviewRef.current) {
|
if (iframeRef.current) {
|
||||||
if (loadTimeout.current) {
|
iframeRef.current.src = serverUrl;
|
||||||
clearTimeout(loadTimeout.current);
|
|
||||||
loadTimeout.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
webviewRef.current.src = serverUrl;
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
}
|
}
|
||||||
@@ -386,28 +275,14 @@ export function ElectronLoginForm({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isAuthenticating && (
|
|
||||||
<div
|
|
||||||
className="absolute inset-0 flex items-center justify-center bg-dark-bg/80 z-40"
|
|
||||||
style={{ marginTop: "60px" }}
|
|
||||||
>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
||||||
<span className="ml-3 text-muted-foreground">
|
|
||||||
{t("auth.authenticating")}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<webview
|
<iframe
|
||||||
ref={webviewRef}
|
ref={iframeRef}
|
||||||
src={serverUrl}
|
src={serverUrl}
|
||||||
className="w-full h-full border-0"
|
className="w-full h-full border-0"
|
||||||
partition="persist:termix"
|
title="Server Authentication"
|
||||||
allowpopups="false"
|
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-storage-access-by-user-activation allow-top-navigation allow-top-navigation-by-user-activation allow-modals allow-downloads"
|
||||||
style={{ width: "100%", height: "100%" }}
|
allow="clipboard-read; clipboard-write; cross-origin-isolated; camera; microphone; geolocation"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const languages = [
|
|||||||
name: "Brazilian Portuguese",
|
name: "Brazilian Portuguese",
|
||||||
nativeName: "Português Brasileiro",
|
nativeName: "Português Brasileiro",
|
||||||
},
|
},
|
||||||
|
{ code: "ru", name: "Russian", nativeName: "Русский" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export function LanguageSwitcher() {
|
export function LanguageSwitcher() {
|
||||||
|
|||||||
@@ -342,6 +342,7 @@ function createApiInstance(
|
|||||||
|
|
||||||
import("sonner").then(({ toast }) => {
|
import("sonner").then(({ toast }) => {
|
||||||
toast.warning("Session expired. Please log in again.");
|
toast.warning("Session expired. Please log in again.");
|
||||||
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentPath = window.location.pathname;
|
const currentPath = window.location.pathname;
|
||||||
@@ -1944,6 +1945,53 @@ export async function getUserList(): Promise<{ users: UserInfo[] }> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSessions(): Promise<{
|
||||||
|
sessions: {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
username?: string;
|
||||||
|
deviceType: string;
|
||||||
|
deviceInfo: string;
|
||||||
|
createdAt: string;
|
||||||
|
expiresAt: string;
|
||||||
|
lastActiveAt: string;
|
||||||
|
jwtToken: string;
|
||||||
|
isRevoked?: boolean;
|
||||||
|
}[];
|
||||||
|
}> {
|
||||||
|
try {
|
||||||
|
const response = await authApi.get("/users/sessions");
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
handleApiError(error, "fetch sessions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function revokeSession(
|
||||||
|
sessionId: string,
|
||||||
|
): Promise<{ success: boolean; message: string }> {
|
||||||
|
try {
|
||||||
|
const response = await authApi.delete(`/users/sessions/${sessionId}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
handleApiError(error, "revoke session");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function revokeAllUserSessions(
|
||||||
|
userId: string,
|
||||||
|
): Promise<{ success: boolean; message: string }> {
|
||||||
|
try {
|
||||||
|
const response = await authApi.post("/users/sessions/revoke-all", {
|
||||||
|
targetUserId: userId,
|
||||||
|
exceptCurrent: false,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
handleApiError(error, "revoke all user sessions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function makeUserAdmin(
|
export async function makeUserAdmin(
|
||||||
username: string,
|
username: string,
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<Record<string, unknown>> {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export function Auth({
|
|||||||
const [signupConfirmPassword, setSignupConfirmPassword] = useState("");
|
const [signupConfirmPassword, setSignupConfirmPassword] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [oidcLoading, setOidcLoading] = useState(false);
|
const [oidcLoading, setOidcLoading] = useState(false);
|
||||||
const [, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
||||||
const [firstUser, setFirstUser] = useState(false);
|
const [firstUser, setFirstUser] = useState(false);
|
||||||
const [firstUserToastShown, setFirstUserToastShown] = useState(false);
|
const [firstUserToastShown, setFirstUserToastShown] = useState(false);
|
||||||
@@ -115,6 +115,7 @@ export function Auth({
|
|||||||
const [totpCode, setTotpCode] = useState("");
|
const [totpCode, setTotpCode] = useState("");
|
||||||
const [totpTempToken, setTotpTempToken] = useState("");
|
const [totpTempToken, setTotpTempToken] = useState("");
|
||||||
const [totpLoading, setTotpLoading] = useState(false);
|
const [totpLoading, setTotpLoading] = useState(false);
|
||||||
|
const [mobileAuthSuccess, setMobileAuthSuccess] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInternalLoggedIn(loggedIn);
|
setInternalLoggedIn(loggedIn);
|
||||||
@@ -238,20 +239,25 @@ export function Auth({
|
|||||||
|
|
||||||
const [meRes] = await Promise.all([getUserInfo()]);
|
const [meRes] = await Promise.all([getUserInfo()]);
|
||||||
|
|
||||||
setInternalLoggedIn(true);
|
|
||||||
setLoggedIn(true);
|
setLoggedIn(true);
|
||||||
setIsAdmin(!!meRes.is_admin);
|
setIsAdmin(!!meRes.is_admin);
|
||||||
setUsername(meRes.username || null);
|
setUsername(meRes.username || null);
|
||||||
setUserId(meRes.userId || null);
|
setUserId(meRes.userId || null);
|
||||||
setDbError(null);
|
setDbError(null);
|
||||||
|
postJWTToWebView();
|
||||||
|
|
||||||
|
if (isReactNativeWebView()) {
|
||||||
|
setMobileAuthSuccess(true);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onAuthSuccess({
|
onAuthSuccess({
|
||||||
isAdmin: !!meRes.is_admin,
|
isAdmin: !!meRes.is_admin,
|
||||||
username: meRes.username || null,
|
username: meRes.username || null,
|
||||||
userId: meRes.userId || null,
|
userId: meRes.userId || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
postJWTToWebView();
|
|
||||||
|
|
||||||
setInternalLoggedIn(true);
|
setInternalLoggedIn(true);
|
||||||
if (tab === "signup") {
|
if (tab === "signup") {
|
||||||
setSignupConfirmPassword("");
|
setSignupConfirmPassword("");
|
||||||
@@ -271,7 +277,7 @@ export function Auth({
|
|||||||
error?.response?.data?.error ||
|
error?.response?.data?.error ||
|
||||||
error?.message ||
|
error?.message ||
|
||||||
t("errors.unknownError");
|
t("errors.unknownError");
|
||||||
toast.error(errorMessage);
|
setError(errorMessage);
|
||||||
setInternalLoggedIn(false);
|
setInternalLoggedIn(false);
|
||||||
setLoggedIn(false);
|
setLoggedIn(false);
|
||||||
setIsAdmin(false);
|
setIsAdmin(false);
|
||||||
@@ -299,11 +305,11 @@ export function Auth({
|
|||||||
message?: string;
|
message?: string;
|
||||||
response?: { data?: { error?: string } };
|
response?: { data?: { error?: string } };
|
||||||
};
|
};
|
||||||
toast.error(
|
const errorMessage =
|
||||||
error?.response?.data?.error ||
|
error?.response?.data?.error ||
|
||||||
error?.message ||
|
error?.message ||
|
||||||
t("errors.failedPasswordReset"),
|
t("errors.failedPasswordReset");
|
||||||
);
|
setError(errorMessage);
|
||||||
} finally {
|
} finally {
|
||||||
setResetLoading(false);
|
setResetLoading(false);
|
||||||
}
|
}
|
||||||
@@ -319,7 +325,9 @@ export function Auth({
|
|||||||
toast.success(t("messages.codeVerified"));
|
toast.success(t("messages.codeVerified"));
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const error = err as { response?: { data?: { error?: string } } };
|
const error = err as { response?: { data?: { error?: string } } };
|
||||||
toast.error(error?.response?.data?.error || t("errors.failedVerifyCode"));
|
const errorMessage =
|
||||||
|
error?.response?.data?.error || t("errors.failedVerifyCode");
|
||||||
|
setError(errorMessage);
|
||||||
} finally {
|
} finally {
|
||||||
setResetLoading(false);
|
setResetLoading(false);
|
||||||
}
|
}
|
||||||
@@ -358,9 +366,9 @@ export function Auth({
|
|||||||
resetPasswordState();
|
resetPasswordState();
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const error = err as { response?: { data?: { error?: string } } };
|
const error = err as { response?: { data?: { error?: string } } };
|
||||||
toast.error(
|
const errorMessage =
|
||||||
error?.response?.data?.error || t("errors.failedCompleteReset"),
|
error?.response?.data?.error || t("errors.failedCompleteReset");
|
||||||
);
|
setError(errorMessage);
|
||||||
} finally {
|
} finally {
|
||||||
setResetLoading(false);
|
setResetLoading(false);
|
||||||
}
|
}
|
||||||
@@ -403,23 +411,26 @@ export function Auth({
|
|||||||
localStorage.setItem("jwt", res.token);
|
localStorage.setItem("jwt", res.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInternalLoggedIn(true);
|
|
||||||
setLoggedIn(true);
|
setLoggedIn(true);
|
||||||
setIsAdmin(!!res.is_admin);
|
setIsAdmin(!!res.is_admin);
|
||||||
setUsername(res.username || null);
|
setUsername(res.username || null);
|
||||||
setUserId(res.userId || null);
|
setUserId(res.userId || null);
|
||||||
setDbError(null);
|
setDbError(null);
|
||||||
|
|
||||||
setTimeout(() => {
|
postJWTToWebView();
|
||||||
|
|
||||||
|
if (isReactNativeWebView()) {
|
||||||
|
setMobileAuthSuccess(true);
|
||||||
|
setTotpLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onAuthSuccess({
|
onAuthSuccess({
|
||||||
isAdmin: !!res.is_admin,
|
isAdmin: !!res.is_admin,
|
||||||
username: res.username || null,
|
username: res.username || null,
|
||||||
userId: res.userId || null,
|
userId: res.userId || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
postJWTToWebView();
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
setInternalLoggedIn(true);
|
setInternalLoggedIn(true);
|
||||||
setTotpRequired(false);
|
setTotpRequired(false);
|
||||||
setTotpCode("");
|
setTotpCode("");
|
||||||
@@ -443,7 +454,7 @@ export function Auth({
|
|||||||
setTab("login");
|
setTab("login");
|
||||||
toast.error(t("errors.sessionExpired"));
|
toast.error(t("errors.sessionExpired"));
|
||||||
} else {
|
} else {
|
||||||
toast.error(errorMessage);
|
setError(errorMessage);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setTotpLoading(false);
|
setTotpLoading(false);
|
||||||
@@ -471,7 +482,7 @@ export function Auth({
|
|||||||
error?.response?.data?.error ||
|
error?.response?.data?.error ||
|
||||||
error?.message ||
|
error?.message ||
|
||||||
t("errors.failedOidcLogin");
|
t("errors.failedOidcLogin");
|
||||||
toast.error(errorMessage);
|
setError(errorMessage);
|
||||||
setOidcLoading(false);
|
setOidcLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,7 +493,8 @@ export function Auth({
|
|||||||
const error = urlParams.get("error");
|
const error = urlParams.get("error");
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
toast.error(`${t("errors.oidcAuthFailed")}: ${error}`);
|
const errorMessage = `${t("errors.oidcAuthFailed")}: ${error}`;
|
||||||
|
setError(errorMessage);
|
||||||
setOidcLoading(false);
|
setOidcLoading(false);
|
||||||
window.history.replaceState({}, document.title, window.location.pathname);
|
window.history.replaceState({}, document.title, window.location.pathname);
|
||||||
return;
|
return;
|
||||||
@@ -494,20 +506,30 @@ export function Auth({
|
|||||||
|
|
||||||
getUserInfo()
|
getUserInfo()
|
||||||
.then((meRes) => {
|
.then((meRes) => {
|
||||||
setInternalLoggedIn(true);
|
|
||||||
setLoggedIn(true);
|
setLoggedIn(true);
|
||||||
setIsAdmin(!!meRes.is_admin);
|
setIsAdmin(!!meRes.is_admin);
|
||||||
setUsername(meRes.username || null);
|
setUsername(meRes.username || null);
|
||||||
setUserId(meRes.userId || null);
|
setUserId(meRes.userId || null);
|
||||||
setDbError(null);
|
setDbError(null);
|
||||||
|
postJWTToWebView();
|
||||||
|
|
||||||
|
if (isReactNativeWebView()) {
|
||||||
|
setMobileAuthSuccess(true);
|
||||||
|
setOidcLoading(false);
|
||||||
|
window.history.replaceState(
|
||||||
|
{},
|
||||||
|
document.title,
|
||||||
|
window.location.pathname,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onAuthSuccess({
|
onAuthSuccess({
|
||||||
isAdmin: !!meRes.is_admin,
|
isAdmin: !!meRes.is_admin,
|
||||||
username: meRes.username || null,
|
username: meRes.username || null,
|
||||||
userId: meRes.userId || null,
|
userId: meRes.userId || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
postJWTToWebView();
|
|
||||||
|
|
||||||
setInternalLoggedIn(true);
|
setInternalLoggedIn(true);
|
||||||
window.history.replaceState(
|
window.history.replaceState(
|
||||||
{},
|
{},
|
||||||
@@ -516,7 +538,7 @@ export function Auth({
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast.error(t("errors.failedUserInfo"));
|
setError(t("errors.failedUserInfo"));
|
||||||
setInternalLoggedIn(false);
|
setInternalLoggedIn(false);
|
||||||
setLoggedIn(false);
|
setLoggedIn(false);
|
||||||
setIsAdmin(false);
|
setIsAdmin(false);
|
||||||
@@ -562,20 +584,53 @@ export function Auth({
|
|||||||
style={{ maxHeight: "calc(100vh - 1rem)" }}
|
style={{ maxHeight: "calc(100vh - 1rem)" }}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{isReactNativeWebView() && (
|
{isReactNativeWebView() && !mobileAuthSuccess && (
|
||||||
<Alert className="mb-4 border-blue-500 bg-blue-500/10">
|
<Alert className="mb-4 border-blue-500 bg-blue-500/10">
|
||||||
<Smartphone className="h-4 w-4" />
|
<Smartphone className="h-4 w-4" />
|
||||||
<AlertTitle>{t("auth.mobileApp")}</AlertTitle>
|
<AlertTitle>{t("auth.mobileApp")}</AlertTitle>
|
||||||
<AlertDescription>{t("auth.loggingInToMobileApp")}</AlertDescription>
|
<AlertDescription>{t("auth.loggingInToMobileApp")}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
{dbError && (
|
{isReactNativeWebView() && mobileAuthSuccess && (
|
||||||
|
<div className="flex flex-col items-center justify-center h-64 gap-4">
|
||||||
|
<div className="w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center">
|
||||||
|
<svg
|
||||||
|
className="w-10 h-10 text-green-500"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M5 13l4 4L19 7"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div className="text-center">
|
||||||
|
<h2 className="text-xl font-bold mb-2">
|
||||||
|
{t("messages.loginSuccess")}
|
||||||
|
</h2>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{t("auth.redirectingToApp")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!mobileAuthSuccess && error && (
|
||||||
|
<Alert variant="destructive" className="mb-4">
|
||||||
|
<AlertTitle>{t("common.error", "Error")}</AlertTitle>
|
||||||
|
<AlertDescription>{error}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{!mobileAuthSuccess && dbError && (
|
||||||
<Alert variant="destructive" className="mb-4">
|
<Alert variant="destructive" className="mb-4">
|
||||||
<AlertTitle>Error</AlertTitle>
|
<AlertTitle>Error</AlertTitle>
|
||||||
<AlertDescription>{dbError}</AlertDescription>
|
<AlertDescription>{dbError}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
{totpRequired && (
|
{!mobileAuthSuccess && totpRequired && (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<div className="mb-6 text-center">
|
<div className="mb-6 text-center">
|
||||||
<h2 className="text-xl font-bold mb-1">
|
<h2 className="text-xl font-bold mb-1">
|
||||||
@@ -628,7 +683,7 @@ export function Auth({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{internalLoggedIn && !authLoading && (
|
{!mobileAuthSuccess && internalLoggedIn && !authLoading && (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<div className="mb-6 text-center">
|
<div className="mb-6 text-center">
|
||||||
<h2 className="text-xl font-bold mb-1">
|
<h2 className="text-xl font-bold mb-1">
|
||||||
@@ -652,7 +707,10 @@ export function Auth({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!internalLoggedIn && !authLoading && !totpRequired && (
|
{!mobileAuthSuccess &&
|
||||||
|
!internalLoggedIn &&
|
||||||
|
!authLoading &&
|
||||||
|
!totpRequired && (
|
||||||
<>
|
<>
|
||||||
{(() => {
|
{(() => {
|
||||||
const hasLogin = passwordLoginAllowed && !firstUser;
|
const hasLogin = passwordLoginAllowed && !firstUser;
|
||||||
@@ -765,7 +823,9 @@ export function Auth({
|
|||||||
disabled={oidcLoading}
|
disabled={oidcLoading}
|
||||||
onClick={handleOIDCLogin}
|
onClick={handleOIDCLogin}
|
||||||
>
|
>
|
||||||
{oidcLoading ? Spinner : t("auth.loginWithExternal")}
|
{oidcLoading
|
||||||
|
? Spinner
|
||||||
|
: t("auth.loginWithExternal")}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -802,7 +862,9 @@ export function Auth({
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="w-full h-11 text-base font-semibold"
|
className="w-full h-11 text-base font-semibold"
|
||||||
disabled={resetLoading || !localUsername.trim()}
|
disabled={
|
||||||
|
resetLoading || !localUsername.trim()
|
||||||
|
}
|
||||||
onClick={handleInitiatePasswordReset}
|
onClick={handleInitiatePasswordReset}
|
||||||
>
|
>
|
||||||
{resetLoading
|
{resetLoading
|
||||||
@@ -945,7 +1007,10 @@ export function Auth({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<form className="flex flex-col gap-5" onSubmit={handleSubmit}>
|
<form
|
||||||
|
className="flex flex-col gap-5"
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label htmlFor="username">{t("common.username")}</Label>
|
<Label htmlFor="username">{t("common.username")}</Label>
|
||||||
<Input
|
<Input
|
||||||
@@ -1032,7 +1097,10 @@ export function Auth({
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full h-11 text-base font-semibold"
|
className="w-full h-11 text-base font-semibold"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
window.open("https://docs.termix.site/install", "_blank")
|
window.open(
|
||||||
|
"https://docs.termix.site/install",
|
||||||
|
"_blank",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{t("mobile.viewMobileAppDocs")}
|
{t("mobile.viewMobileAppDocs")}
|
||||||
|
|||||||
Reference in New Issue
Block a user