Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function App() {
})
}, (error) => {
console.log("No valid user detected")
// opt-out current user if it the token is expired
setUser({username: "no-user", email: "", icon: process.env.PUBLIC_URL + '/images/avatar-1.png'})
})
}, [])

Expand Down
11 changes: 10 additions & 1 deletion client/src/pages/CreateContest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'
import React, { useContext } from 'react'
import { Grid, Paper } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'

import CreateContestForm from '../components/CreateContestForm'
import { UserContext } from '../App'
import { Redirect } from 'react-router-dom'

const useStyles = makeStyles((theme) => ({
pageContainer: {
Expand All @@ -21,6 +23,13 @@ const useStyles = makeStyles((theme) => ({

export default function CreateContest() {
const classes = useStyles()
const {user, setUser} = useContext(UserContext)

if (user.username === "no-user") {
return (
<Redirect to='/login'/>
)
}

return (
<Grid container justify='center' className={classes.pageContainer}>
Expand Down
9 changes: 8 additions & 1 deletion client/src/pages/SocketioConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { UserContext } from '../App';
import { getMsgLog } from '../apiCalls';
import { Button, Form, InputGroup } from 'react-bootstrap';
import { makeStyles, Typography } from '@material-ui/core';
import { useHistory, useLocation } from 'react-router-dom';
import { Redirect, useHistory, useLocation } from 'react-router-dom';

let socket = io.connect(null, {port:5000, rememberTransport: false});

Expand Down Expand Up @@ -82,6 +82,13 @@ function Socketio() {
history.push('/profile/'+room.user.username)
}


if (user.username === "no-user") {
return (
<Redirect to='/login'/>
)
}

return (
<CurrentSessionContext.Provider value={{room, setRoom}}>
<SessionsContext.Provider value={{sessions, setSessions}}>
Expand Down
13 changes: 11 additions & 2 deletions client/src/pages/SubmitDesign.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { useHistory } from 'react-router-dom'
import React, { useContext } from 'react'
import { Redirect, useHistory } from 'react-router-dom'
import { makeStyles } from '@material-ui/core/styles'
import { Paper, Typography, Button, Box } from '@material-ui/core'
import { useDropzone } from 'react-dropzone'
import { UserContext } from '../App'

const useStyles = makeStyles((theme) => ({
pageContainer: {
Expand Down Expand Up @@ -63,6 +64,7 @@ const useStyles = makeStyles((theme) => ({
export default function SubmitDesign(props) {
const history = useHistory()
const classes = useStyles()
const {user, setUser} = useContext(UserContext);
const {
acceptedFiles,
fileRejections,
Expand Down Expand Up @@ -115,6 +117,13 @@ export default function SubmitDesign(props) {
})
}

if (user.username === "no-user") {
return (
<Redirect to='/login'/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm with this, if user doesn't load just yet, will this redirect to login? for example if you refresh this submit design page, the user i'm guessing won't load as fast as this page gets rendered

)
}


return (
<div className={classes.pageContainer}>
<div {...getRootProps({ className: 'dropzone' })}>
Expand Down