- Fix redirects to /login for auth required pages
- Add handling for 401/429 + No connection responses in API calls
- Add background workers for Go (clear out password resets)
- Fixed timezone issues
This commit is contained in:
Daniel Mason 2021-04-02 22:24:00 +13:00
parent fd615102a8
commit 9866dea36b
Signed by: idanoo
GPG key ID: 387387CDBC02F132
33 changed files with 795 additions and 248 deletions

View file

@ -22,8 +22,8 @@ const Admin = () => {
if (data.configs) {
setConfigs(data.configs);
setToggle(data.configs.REGISTRATION_ENABLED === "1")
setLoading(false);
}
setLoading(false);
})
}, [])
@ -31,6 +31,14 @@ const Admin = () => {
setToggle(!toggle);
};
if (!user) {
history.push("/login")
}
if (user && !user.admin) {
history.push("/Dashboard")
}
if (loading) {
return (
<div className="pageWrapper">
@ -39,9 +47,7 @@ const Admin = () => {
)
}
if (!user || !user.admin) {
history.push("/login")
}
return (
<div className="pageWrapper">

View file

@ -8,7 +8,7 @@ import ScrobbleTable from "../Components/ScrobbleTable";
import AuthContext from '../Contexts/AuthContext';
const Dashboard = () => {
// const history = useHistory();
const history = useHistory();
let { user } = useContext(AuthContext);
let [loading, setLoading] = useState(true);
let [dashboardData, setDashboardData] = useState({});
@ -24,6 +24,10 @@ const Dashboard = () => {
})
}, [user])
if (!user) {
history.push("/login")
}
if (loading) {
return (
<div className="pageWrapper">
@ -37,10 +41,12 @@ const Dashboard = () => {
<h1>
{user.username}'s Dashboard!
</h1>
<div className="dashboardBody">
{loading
? <ScaleLoader color="#6AD7E5" size={60} />
: <ScrobbleTable data={dashboardData.items} />
}
</div>
</div>
);
}

View file

@ -63,7 +63,7 @@ const Login = () => {
className="loginButton"
onClick={redirectReset}
disabled={loading}
>{loading ? <ScaleLoader color="#FFF" size={35} /> : "Reset Password"}</Button>
>Reset Password</Button>
</Form>
</Formik>
</div>

View file

@ -5,6 +5,8 @@ import { useHistory } from "react-router";
import AuthContext from '../Contexts/AuthContext';
import ScaleLoader from 'react-spinners/ScaleLoader';
import { getUser } from '../Api/index'
import { Button } from 'reactstrap';
import { spotifyConnectionRequest, spotifyDisonnectionRequest } from '../Api/index'
const User = () => {
const history = useHistory();
@ -12,6 +14,7 @@ const User = () => {
const [loading, setLoading] = useState(true);
const [userdata, setUserdata] = useState({});
useEffect(() => {
if (!user) {
return
@ -24,6 +27,10 @@ const User = () => {
})
}, [user])
if (!user) {
history.push("/login")
}
if (loading) {
return (
<div className="pageWrapper">
@ -32,10 +39,6 @@ const User = () => {
)
}
if (!user) {
history.push("/login")
}
return (
<div className="pageWrapper">
<h1>
@ -44,7 +47,25 @@ const User = () => {
<p className="userBody">
Created At: {userdata.created_at}<br/>
Email: {userdata.email}<br/>
Verified: {userdata.verified ? '✓' : '✖'}
Verified: {userdata.verified ? '✓' : '✖'}<br/>
{userdata.spotify_username
? <div>Spotify Account: {userdata.spotify_username}<br/><br/>
<Button
color="secondary"
type="button"
className="loginButton"
onClick={spotifyDisonnectionRequest}
>Disconnect Spotify</Button></div>
: <div>
<br/>
<Button
color="primary"
type="button"
className="loginButton"
onClick={spotifyConnectionRequest}
>Connect To Spotify</Button>
</div>
}
</p>
</div>
);