diff options
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/Activate.js | 15 | ||||
| -rw-r--r-- | frontend/src/App.js | 19 | ||||
| -rw-r--r-- | frontend/src/Register.js | 6 |
3 files changed, 32 insertions, 8 deletions
diff --git a/frontend/src/Activate.js b/frontend/src/Activate.js index 8a420f4..17d980e 100644 --- a/frontend/src/Activate.js +++ b/frontend/src/Activate.js @@ -2,14 +2,19 @@ import React, { useEffect, useState } from 'react'; import axios from './axios'; import { Link } from '@reach/router'; -const Activate = ({ activationToken }) => { +import userState from './UserState'; + +const Activate = ({ user, activationToken }) => { const [ data, setData ] = useState({}); useEffect(() => { (async () => { try { - await axios.post('/activate', { activationToken }); + const resp = await axios.post('/activate', { activationToken }); + const { username } = resp.data; + user.authError = null; + user.username = username; setData({ - message: 'Account succesfully activated. You can now log in.', + message: 'Account succesfully activated. You are now logged in.', }); } catch (err) { setData({ @@ -27,10 +32,10 @@ const Activate = ({ activationToken }) => { {data.error} </div> <div>{data.message}</div> - {data.message && <Link to="/login">To login page</Link>} + {data.message && <Link to="/">To front page</Link>} </div> </div> ); }; -export default Activate; +export default props => <Activate user={userState} {...props} />; diff --git a/frontend/src/App.js b/frontend/src/App.js index 38d8aef..51ba18c 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -9,7 +9,7 @@ import './App.css'; import axios from './axios'; import Activate from './Activate'; -const App = () => { +const LoggedInRoutes = props => { useEffect(() => { const fetchUserInfo = async () => { try { @@ -24,8 +24,23 @@ const App = () => { fetchUserInfo(); }, []); + return props.children; +}; + +const App = () => { + const fetchUserInfo = async () => { + try { + const resp = await axios.get('/user'); + const { username } = resp.data; + userState.username = username; + } catch (err) { + userState.authError = err; + console.error(err); + } + }; + fetchUserInfo(); return ( - <div className="App"> + <div className="container"> <Router> <Login path="/login" /> <Register path="/register" /> diff --git a/frontend/src/Register.js b/frontend/src/Register.js index 97a5992..c2d7e98 100644 --- a/frontend/src/Register.js +++ b/frontend/src/Register.js @@ -18,7 +18,7 @@ const Register = () => { const { username } = resp.data; userState.authError = null; userState.username = username; - navigate('/'); + setData({ submitted: true }); } catch (err) { if (err.response && err.response.data) { setData({ @@ -31,6 +31,10 @@ const Register = () => { } }; + if (data.submitted) { + return <h1>You should be receiving an account activation email shortly.</h1>; + } + return ( <form onSubmit={handleSubmit(onSubmit)}> <h1 className="title">Register new account</h1> |
