forbidding going back for registr and login

This commit is contained in:
Tatiana Nikolaeva 2025-06-03 09:59:52 +05:00
parent e6e2f68eb0
commit 4d96cbaab1
5 changed files with 23 additions and 2 deletions

View file

@ -27,7 +27,7 @@ const LoginForm = () => {
else {
const responseData = await authUser({email, password});
if (responseData && !responseData.error)
navigate('/my-surveys');
navigate('/my-surveys', {replace: true});
else
setError('Неверный логин или пароль')
}

View file

@ -1,6 +1,7 @@
/*Logo.module.css*/
.logo {
outline: none;
padding: 0;
margin: 0 100px 0 40px;
display: flex;

View file

@ -39,7 +39,7 @@ const RegisterForm = () => {
if (responseData && !responseData.error) {
console.log('Регистрация успешна');
localStorage.setItem("user", JSON.stringify(responseData.user));
navigate('/my-surveys');
navigate('/my-surveys', {replace: true});
}
else if (responseData.status === 409){
setError('Аккаунт с такой почтой уже зарегистрирован');

View file

@ -23,6 +23,7 @@
width: 80%;
display: block;
border: none;
outline: none;
margin: 0 auto 13px;
background-color: white;
text-align: center;
@ -75,6 +76,7 @@
.description {
min-height: 24px;
border: none;
outline: none;
font-size: 16px;
font-weight: 500;
text-align: center;
@ -88,6 +90,7 @@
.desc{
font-size: 20px;
outline: none;
font-weight: 500;
background-color: white;
max-width: 80%;

View file

@ -2,6 +2,7 @@ import styles from './AuthForm.module.css';
import LoginForm from "../../components/LoginForm/LoginForm.tsx";
import RegisterForm from "../../components/RegisterForm/RegisterForm.tsx";
import {useLocation} from "react-router-dom";
import {useEffect} from "react";
const AuthForm = () => {
@ -9,6 +10,22 @@ const AuthForm = () => {
const isLoginPage = location.pathname === '/login';
const isRegisterPage = location.pathname === '/register';
useEffect(() => {
if (isLoginPage || isRegisterPage) {
window.history.pushState(null, "", window.location.href);
const handlePopState = () => {
window.history.pushState(null, "", window.location.href);
};
window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
}
}, [isLoginPage, isRegisterPage]);
let content;
if (isLoginPage) {
content = <LoginForm />;