forbidding going back for registr and login
This commit is contained in:
parent
e6e2f68eb0
commit
4d96cbaab1
5 changed files with 23 additions and 2 deletions
|
|
@ -27,7 +27,7 @@ const LoginForm = () => {
|
||||||
else {
|
else {
|
||||||
const responseData = await authUser({email, password});
|
const responseData = await authUser({email, password});
|
||||||
if (responseData && !responseData.error)
|
if (responseData && !responseData.error)
|
||||||
navigate('/my-surveys');
|
navigate('/my-surveys', {replace: true});
|
||||||
else
|
else
|
||||||
setError('Неверный логин или пароль')
|
setError('Неверный логин или пароль')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/*Logo.module.css*/
|
/*Logo.module.css*/
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
|
outline: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0 100px 0 40px;
|
margin: 0 100px 0 40px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ const RegisterForm = () => {
|
||||||
if (responseData && !responseData.error) {
|
if (responseData && !responseData.error) {
|
||||||
console.log('Регистрация успешна');
|
console.log('Регистрация успешна');
|
||||||
localStorage.setItem("user", JSON.stringify(responseData.user));
|
localStorage.setItem("user", JSON.stringify(responseData.user));
|
||||||
navigate('/my-surveys');
|
navigate('/my-surveys', {replace: true});
|
||||||
}
|
}
|
||||||
else if (responseData.status === 409){
|
else if (responseData.status === 409){
|
||||||
setError('Аккаунт с такой почтой уже зарегистрирован');
|
setError('Аккаунт с такой почтой уже зарегистрирован');
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
width: 80%;
|
width: 80%;
|
||||||
display: block;
|
display: block;
|
||||||
border: none;
|
border: none;
|
||||||
|
outline: none;
|
||||||
margin: 0 auto 13px;
|
margin: 0 auto 13px;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
@ -75,6 +76,7 @@
|
||||||
.description {
|
.description {
|
||||||
min-height: 24px;
|
min-height: 24px;
|
||||||
border: none;
|
border: none;
|
||||||
|
outline: none;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
@ -88,6 +90,7 @@
|
||||||
|
|
||||||
.desc{
|
.desc{
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
outline: none;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import styles from './AuthForm.module.css';
|
||||||
import LoginForm from "../../components/LoginForm/LoginForm.tsx";
|
import LoginForm from "../../components/LoginForm/LoginForm.tsx";
|
||||||
import RegisterForm from "../../components/RegisterForm/RegisterForm.tsx";
|
import RegisterForm from "../../components/RegisterForm/RegisterForm.tsx";
|
||||||
import {useLocation} from "react-router-dom";
|
import {useLocation} from "react-router-dom";
|
||||||
|
import {useEffect} from "react";
|
||||||
|
|
||||||
|
|
||||||
const AuthForm = () => {
|
const AuthForm = () => {
|
||||||
|
|
@ -9,6 +10,22 @@ const AuthForm = () => {
|
||||||
const isLoginPage = location.pathname === '/login';
|
const isLoginPage = location.pathname === '/login';
|
||||||
const isRegisterPage = location.pathname === '/register';
|
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;
|
let content;
|
||||||
if (isLoginPage) {
|
if (isLoginPage) {
|
||||||
content = <LoginForm />;
|
content = <LoginForm />;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue