Merge pull request #1 from C4theBomb/bugfix-login-screen
Bugfix login screen
This commit is contained in:
commit
008a43fe30
8 changed files with 34 additions and 15 deletions
|
|
@ -24,7 +24,10 @@ function App() {
|
|||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path='' element={<Navbar token={token} />}>
|
||||
<Route index element={<MainPage />} />
|
||||
<Route
|
||||
index
|
||||
element={<MainPage setToken={setToken} />}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path='login'
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
import OrgUnit from './utils/OrgUnit';
|
||||
import StackItem from './utils/StackItem';
|
||||
|
||||
function MainPage() {
|
||||
function MainPage({ setToken }) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [ownedOrgs, setOwnedOrgs] = useState([]);
|
||||
|
|
@ -33,9 +33,7 @@ function MainPage() {
|
|||
if (!Cookies.get('token')) {
|
||||
navigate('/login');
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {}, []);
|
||||
}, [navigate, setToken]);
|
||||
|
||||
useEffect(() => {
|
||||
getMemberOrgs();
|
||||
|
|
@ -71,7 +69,13 @@ function MainPage() {
|
|||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
if (e.response.status === 511) {
|
||||
console.log(e.response);
|
||||
Cookies.remove('token');
|
||||
Cookies.remove('userID');
|
||||
|
||||
setToken(() => false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +97,15 @@ function MainPage() {
|
|||
};
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (e.response.status === 511) {
|
||||
console.log(e.response);
|
||||
Cookies.remove('token');
|
||||
Cookies.remove('userID');
|
||||
|
||||
setToken(() => false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ function Login({ setToken }) {
|
|||
.post(`${process.env.REACT_APP_API_ROOT}/auth/login`, form)
|
||||
.then((response) => {
|
||||
Cookies.set('token', response.data.token, {
|
||||
expires: form.remember ? 3650 : 1,
|
||||
expires: form.remember ? 3650 : null,
|
||||
});
|
||||
Cookies.set('userID', response.data.userID, {
|
||||
expires: form.remember ? 3650 : 1,
|
||||
expires: form.remember ? 3650 : null,
|
||||
});
|
||||
setToken(true);
|
||||
navigate('/');
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@ function Recover() {
|
|||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
await axios
|
||||
.get(
|
||||
`${process.env.REACT_APP_API_ROOT}/auth/reset-password?${form.email}`
|
||||
)
|
||||
.get(`${process.env.REACT_APP_API_ROOT}/auth/reset-password`, {
|
||||
params: {
|
||||
email: form.email,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
setSuccess(() => response.data);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"install-all": "npm ci && npm ci --prefix client && npm ci --prefix server",
|
||||
"client": "npm start --prefix client",
|
||||
"server": "npm start --prefix server",
|
||||
"dev": "npm run build && npm run server",
|
||||
"build": "npm run env && npm run build --prefix client",
|
||||
"test": "npm run build && npm run server",
|
||||
"install-all": "npm ci && npm ci --prefix client && npm ci --prefix server",
|
||||
"env": "cp .env ./server/.env && cp .env ./client/.env",
|
||||
"package": "tar -czf ./dist.tar.gz ./.github ./.vscode ./client ./node_modules ./server .env .gitignore LICENSE package-lock.json package.json README.md",
|
||||
"dist": "npm run install-all && npm run build && npm run package"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('dotenv').config({ path: `../.env.${process.env.NODE_ENV}` });
|
||||
require('dotenv').config();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ async function RequestReset(req, res, next) {
|
|||
data: {
|
||||
email: result.email,
|
||||
resetRequest: resetRequest.reqID,
|
||||
apiDomainRoot: process.env.REACT_APP_DOMAIN_ROOT,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ async function ResetPassword(req, res, next) {
|
|||
return res.status(400).send('Form missing required information.');
|
||||
}
|
||||
|
||||
const result = await ResetRequest.findOne({ where: { reqID: reqID } });
|
||||
const result = await ResetRequest.findByPk(reqID);
|
||||
|
||||
if (!result) {
|
||||
return res
|
||||
|
|
|
|||
Reference in a new issue