Fixed reset page

This commit is contained in:
2022-12-04 11:48:23 +00:00
parent 6ef0affcf6
commit 36e79a513f
2 changed files with 7 additions and 9 deletions
+7 -8
View File
@@ -1,6 +1,5 @@
import React, { useContext, useRef } from 'react'; import React, { useContext, useRef } from 'react';
import { Link, useNavigate } from 'react-router-dom'; import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import queryString from 'query-string';
import ApplyToBody from '../utilities/apply-to-body'; import ApplyToBody from '../utilities/apply-to-body';
@@ -13,11 +12,11 @@ const Reset = props => {
//context //context
const authTokens = useContext(TokenContext); const authTokens = useContext(TokenContext);
//query //params
const query = queryString.parse(props.location.search); const [params, setParams] = useSearchParams();
//misplaced? //misplaced?
if (authTokens.accessToken || !query.email || !query.token) { if (authTokens.accessToken || !params.email || !params.token) {
navigate("/"); navigate("/");
} }
@@ -34,7 +33,7 @@ const Reset = props => {
<h1 className='text centered'>Reset Password</h1> <h1 className='text centered'>Reset Password</h1>
<form className='constrained' onSubmit={async evt => { <form className='constrained' onSubmit={async evt => {
evt.preventDefault(); evt.preventDefault();
const [err, redirect] = await update(passwordRef.current.value, retypeRef.current.value, query); const [err, redirect] = await update(passwordRef.current.value, retypeRef.current.value, params);
if (err) { if (err) {
alert(err); alert(err);
@@ -59,7 +58,7 @@ const Reset = props => {
); );
}; };
const update = async (password, retype, query) => { const update = async (password, retype, params) => {
if (password != retype) { if (password != retype) {
return ['Passwords do not match']; return ['Passwords do not match'];
} }
@@ -68,7 +67,7 @@ const update = async (password, retype, query) => {
return ['Password is too short']; return ['Password is too short'];
} }
const result = await fetch(`${process.env.AUTH_URI}/auth/reset?email=${query.email}&token=${query.token}`, { const result = await fetch(`${process.env.AUTH_URI}/auth/reset?email=${params.email}&token=${params.token}`, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
-1
View File
@@ -41,7 +41,6 @@
"html-webpack-plugin": "^5.5.0", "html-webpack-plugin": "^5.5.0",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"mariadb": "^3.0.2", "mariadb": "^3.0.2",
"query-string": "^4.3.4",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router": "^6.3.0", "react-router": "^6.3.0",