From 0947b64287f7dd39310b7da10c7d8675c090b230 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 25 Feb 2020 15:03:07 +0200 Subject: yep --- frontend/src/Activate.js | 15 ++++++++++----- frontend/src/App.js | 19 +++++++++++++++++-- frontend/src/Register.js | 6 +++++- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'frontend/src') 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}
{data.message}
- {data.message && To login page} + {data.message && To front page} ); }; -export default Activate; +export default 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 ( -
+
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

You should be receiving an account activation email shortly.

; + } + return (

Register new account

-- cgit v1.3