Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
76c3660cb2
commit
977759145e
2 changed files with 14 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
BrowserRouter, Switch, Route, Redirect,
|
BrowserRouter,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import { isAuthenticated } from '../../client/state/auth';
|
import { isAuthenticated } from '../../client/state/auth';
|
||||||
|
@ -11,17 +11,7 @@ import Client from '../templates/client/Client';
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Switch>
|
{ isAuthenticated() ? <Client /> : <Auth />}
|
||||||
<Route exact path="/">
|
|
||||||
{ isAuthenticated() ? <Client /> : <Redirect to="/login" />}
|
|
||||||
</Route>
|
|
||||||
<Route path="/login">
|
|
||||||
{ isAuthenticated() ? <Redirect to="/" /> : <Auth type="login" />}
|
|
||||||
</Route>
|
|
||||||
<Route path="/register">
|
|
||||||
{ isAuthenticated() ? <Redirect to="/" /> : <Auth type="register" />}
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||||
import './Auth.scss';
|
import './Auth.scss';
|
||||||
import ReCAPTCHA from 'react-google-recaptcha';
|
import ReCAPTCHA from 'react-google-recaptcha';
|
||||||
|
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import * as auth from '../../../client/action/auth';
|
import * as auth from '../../../client/action/auth';
|
||||||
import cons from '../../../client/state/cons';
|
import cons from '../../../client/state/cons';
|
||||||
|
|
||||||
|
@ -75,7 +75,8 @@ function normalizeUsername(rawUsername) {
|
||||||
return noLeadingAt.trim();
|
return noLeadingAt.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Auth({ type }) {
|
function Auth() {
|
||||||
|
const [type, setType] = useState('login');
|
||||||
const [process, changeProcess] = useState(null);
|
const [process, changeProcess] = useState(null);
|
||||||
const [homeserver, changeHomeserver] = useState('matrix.org');
|
const [homeserver, changeHomeserver] = useState('matrix.org');
|
||||||
|
|
||||||
|
@ -316,9 +317,16 @@ function Auth({ type }) {
|
||||||
<div className="flex--center">
|
<div className="flex--center">
|
||||||
<Text variant="b2">
|
<Text variant="b2">
|
||||||
{`${(type === 'login' ? 'Don\'t have' : 'Already have')} an account?`}
|
{`${(type === 'login' ? 'Don\'t have' : 'Already have')} an account?`}
|
||||||
<Link to={type === 'login' ? '/register' : '/login'}>
|
<button
|
||||||
|
type="button"
|
||||||
|
style={{ color: 'var(--tc-link)', cursor: 'pointer', margin: '0 var(--sp-ultra-tight)' }}
|
||||||
|
onClick={() => {
|
||||||
|
if (type === 'login') setType('register');
|
||||||
|
else setType('login');
|
||||||
|
}}
|
||||||
|
>
|
||||||
{ type === 'login' ? ' Register' : ' Login' }
|
{ type === 'login' ? ' Register' : ' Login' }
|
||||||
</Link>
|
</button>
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</StaticWrapper>
|
</StaticWrapper>
|
||||||
|
@ -326,10 +334,6 @@ function Auth({ type }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Auth.propTypes = {
|
|
||||||
type: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
function StaticWrapper({ children }) {
|
function StaticWrapper({ children }) {
|
||||||
return (
|
return (
|
||||||
<ScrollView invisible>
|
<ScrollView invisible>
|
||||||
|
|
Loading…
Reference in a new issue