Skip to content

Commit

Permalink
Diagraming first day
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-szczepanski committed Jun 6, 2023
1 parent 0c9873b commit c5c4bd4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The signature is created using a 'secret', which must be kept private (i.e. not
Here, we've used an environment variable called `JWT_SECRET`, which you'll see used in the commands to start the application and run the tests (below). You can change the value of that environment variable to anything you like.
## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
[Trello](https://trello.com/b/ucgll1v8/acebook-airbenders)

## Quickstart

Expand Down
2 changes: 1 addition & 1 deletion api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const tokenChecker = (req, res, next) => {
};

// route setup
app.use("/posts", tokenChecker, postsRouter);
app.use("/posts", tokenChecker, postsRouter); // tokenChecker is a middleware function
app.use("/tokens", tokensRouter);
app.use("/users", usersRouter);

Expand Down
2 changes: 2 additions & 0 deletions api/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const TokenGenerator = require("../models/token_generator");

const PostsController = {
Index: (req, res) => {
// .find is a mongoose method allowing us to get data out of the DB
Post.find(async (err, posts) => {
if (err) {
throw err;
}
const token = await TokenGenerator.jsonwebtoken(req.user_id)
// .json() on the backend sends an http response containing a json.
res.status(200).json({ posts: posts, token: token });
});
},
Expand Down
1 change: 1 addition & 0 deletions api/routes/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const router = express.Router();

const PostsController = require("../controllers/posts");

// .Index and .Create are keys to methods defined in the PostController object
router.get("/", PostsController.Index);
router.post("/", PostsController.Create);

Expand Down
Binary file added diagrams/architecture_diagram_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/architecture_diagram_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion frontend/src/components/feed/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import Post from '../post/Post'

const Feed = ({ navigate }) => {
const [posts, setPosts] = useState([]);
const [token, setToken] = useState(window.localStorage.getItem("token"));
const [token, setToken] = useState(window.localStorage.getItem("token")); // Retrieves a token from the browser storage

useEffect(() => {
// Will send a fetch request if a valid token is found
if(token) {
fetch("/posts", {
headers: {
'Authorization': `Bearer ${token}`
}
})
// This .json() turns a json response into a JS object
.then(response => response.json())
.then(async data => {
window.localStorage.setItem("token", data.token)
Expand Down Expand Up @@ -42,6 +44,7 @@ const Feed = ({ navigate }) => {
</>
)
} else {
// TODO: Possibly an error in route. (Might change to /signup?)
navigate('/signin')
}
}
Expand Down

0 comments on commit c5c4bd4

Please sign in to comment.