mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-23 03:25:07 +03:00
Implement the register screen and make auth work
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
import { useImmer } from "use-immer";
|
||||
import { showChat, showRegister } from "../../navigation";
|
||||
import { AlertsContainer, type Alert, type AlertType } from "../components/Alerts";
|
||||
import { AuthContainer, AuthHeader } from "../components/Auth";
|
||||
import type { ErrorResponse, LoginRequest, LoginResponse } from "../../core/types";
|
||||
import { setUser } from "../../auth/api";
|
||||
import { ensureKeysOnLogin } from "../../auth/crypto";
|
||||
import { API_BASE_URL } from "../../core/config";
|
||||
import { initializeProfile } from "../../userPanel/profile/profile";
|
||||
// import { initializeProfile } from "../../userPanel/profile/profile";
|
||||
import { useRef } from "react";
|
||||
import type { TextField } from "mdui/components/text-field";
|
||||
import { useAppState } from "../state";
|
||||
|
||||
export default function LoginScreen() {
|
||||
const [alerts, updateAlerts] = useImmer<Alert[]>([]);
|
||||
const setCurrentPage = useAppState(state => state.setCurrentPage);
|
||||
|
||||
function showAlert(type: AlertType, message: string) {
|
||||
updateAlerts((alerts) => alerts.push({type: type, message: message}));
|
||||
updateAlerts((alerts) => { alerts.push({type: type, message: message}) });
|
||||
}
|
||||
|
||||
const usernameElement = useRef<TextField>(null);
|
||||
@@ -61,8 +62,8 @@ export default function LoginScreen() {
|
||||
} catch (e) {
|
||||
console.error("Key setup failed:", e);
|
||||
}
|
||||
showChat();
|
||||
initializeProfile(); // Initialize profile after login
|
||||
setCurrentPage("chat");
|
||||
// initializeProfile(); // Initialize profile after login
|
||||
} else {
|
||||
const data: ErrorResponse = await response.json();
|
||||
showAlert("danger", data.message || "Неверное имя пользователя или пароль");
|
||||
@@ -103,7 +104,7 @@ export default function LoginScreen() {
|
||||
<a
|
||||
href="#"
|
||||
className="link"
|
||||
onClick={showRegister}>
|
||||
onClick={() => setCurrentPage("register")}>
|
||||
Зарегистрируйтесь
|
||||
</a>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user