Skip to content

Commit

Permalink
rumseyn/resolve authentication (#254)
Browse files Browse the repository at this point in the history
* Fix CORS error preventing authentication

* Resolve error handling for failed authentication requests

* Resolve miscellaneous nonfatal React errors
  • Loading branch information
n8srumsey authored Nov 16, 2024
1 parent 50a0fa3 commit ec72ac9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
3 changes: 2 additions & 1 deletion client/src/components/nav/TopNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ function LoggedIn(props) {

return (
<>
{navItems.map((item) => (
{navItems.map((item, index) => (
<a
key={index}
href={item.path}
className={`page ${item.className} ${
pathname === item.path ? "curr" : ""
Expand Down
30 changes: 15 additions & 15 deletions client/src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ import "../styles/home.css"
function Home() {
return(
<div id="home">
<div class="section">
<p class="homeHeader">Welcome to MyClassroom</p>
<div className="section">
<p className="homeHeader">Welcome to MyClassroom</p>
<p>Open-Source Classroom Polling Software</p>
</div>

<div class="infoContainer">
<div class="infoConnector"></div>
<div class="infoBox leftBox">
<div className="infoContainer">
<div className="infoConnector"></div>
<div className="infoBox leftBox">
<img src="classroom.png"></img>
<p class="infoText">Create courses and manage lectures easily.</p>
<p className="infoText">Create courses and manage lectures easily.</p>
</div>
<div class="infoBox rightBox">
<div className="infoBox rightBox">
<img src="goal.png"></img>
<p class="infoText">Track student progress and manage grades.</p>
<p className="infoText">Track student progress and manage grades.</p>
</div>
<div class="infoBox leftBox">
<div className="infoBox leftBox">
<img src="lms.png"></img>
<p class="infoText">Seamless integration with educational platforms.</p>
<p className="infoText">Seamless integration with educational platforms.</p>
</div>
<div class="infoBox rightBox">
<div className="infoBox rightBox">
<img src="graph.png"></img>
<p class="infoText">Boost student engagement with interactive polls.</p>
<p className="infoText">Boost student engagement with interactive polls.</p>
</div>
<div class="infoBox leftBox">
<div className="infoBox leftBox">
<img src="school.png"></img>
<p class="infoText">Highly customizable and free to use.</p>
<p className="infoText">Highly customizable and free to use.</p>
</div>
</div>
</div>
)
}

export default Home
export default Home
8 changes: 5 additions & 3 deletions client/src/pages/SingleCoursePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ function DisplayCoursePage(){
const { courseId } = useParams()
let navigate = useNavigate()
const [ course, role, message, error, loading ] = useCourse()
if (role === "student") {
navigate(`/${courseId}/lectures`)
}
useEffect(() => {
if (role === "student") {
navigate(`/${courseId}/lectures`);
}
}, [role, navigate, courseId]);

return <>
{ loading ? <TailSpin visibile={true}/> : (error ? <Notice message={message} error={error ? "error" : ""}/> : <div className="singleCourseContainer">
Expand Down
33 changes: 22 additions & 11 deletions client/src/utils/apiUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,29 @@ const handleRequest = async (method, route, reactOpts, body, params) => {
return responseBody
}
catch (e) { // defines global response behaviors for errors so our application's API calls can be coded with reduced repitition
if (e.response.status === 401 && (reactOpts.overrideRedirect !== true)) {
reactOpts.dispatch(logout())
reactOpts.navigate(`/#?redirect=${location.pathname}`)
if (e.response) {
if (e.response.status === 401 && (reactOpts.overrideRedirect !== true)) {
reactOpts.dispatch(logout())
reactOpts.navigate(`/#?redirect=${location.pathname}`)
}
else if (e.response.status === 403) {
reactOpts.navigate(`/`)
}
return {
message: e.response.data.error,
data: e.response.data,
status: e.response.status,
error: true
}
}
else if (e.response.status === 403) {
reactOpts.navigate(`/`)
}
return {
message: e.response.data.error,
data: e.response.data,
status: e.response.status,
error: true

else {
return {
message: 'An unexpected error occurred. Please try again later.',
data: {},
status: 500,
error: true
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const cors = require("cors");
var express = require("express");
const cookieParser = require("cookie-parser");
const { logger, morganMiddleware } = require("../lib/logger");

if (process.env.NODE_ENV == "development") {
require("dotenv").config({ override: false });
}
Expand All @@ -19,6 +20,7 @@ app.use(
methods: ["GET", "PUT", "POST", "DELETE"],
optionsSuccessStatus: 200,
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization'],
})
);

Expand Down

0 comments on commit ec72ac9

Please # to comment.