@@ -2,23 +2,20 @@ const router = require("express").Router();
2
2
const { Post, User } = require ( "../models" ) ;
3
3
const withAuth = require ( "../utils/auth" ) ;
4
4
5
- router . get ( "/" , withAuth , async ( req , res ) => {
5
+ router . get ( "/" , async ( req , res ) => {
6
6
try {
7
7
// gets all posts to display on the page
8
8
const postData = await Post . findAll ( {
9
9
attributes : [ "title" , "text" , "createdAt" ] ,
10
10
} ) ;
11
11
12
12
const posts = postData . map ( ( post ) => post . get ( { plain : true } ) ) ;
13
-
14
- res . render ( "dashboard" , {
13
+ res . render ( "home" , {
15
14
posts,
16
- //pass data into page
17
- logged_in : true ,
18
- username : req . session . username ,
15
+ logged_in : req . session . logged_in ,
19
16
email : req . session . email ,
20
- // page information
21
- title : "Dashboard " ,
17
+ username : req . session . username ,
18
+ title : "Home " ,
22
19
} ) ;
23
20
} catch ( err ) {
24
21
res . status ( 500 ) . json ( err ) ;
@@ -42,17 +39,27 @@ router.get("/register", (req, res) => {
42
39
} ) ;
43
40
} ) ;
44
41
45
- // * Route for /home
46
- router . get ( "/home" , ( req , res ) => {
47
- console . info ( `${ req . method } request received for homepage` ) ;
42
+ // * Route for /dash
43
+ router . get ( "/dashboard" , async ( req , res ) => {
44
+ console . info ( `${ req . method } request received for dashboard` ) ;
45
+ // gets all posts to display on the page
46
+ const postData = await Post . findAll ( {
47
+ attributes : [ "title" , "text" , "createdAt" ] ,
48
+ } ) ;
49
+
50
+ const posts = postData . map ( ( post ) => post . get ( { plain : true } ) ) ;
51
+
48
52
if ( ! req . session . logged_in ) {
49
53
res . redirect ( "/login" ) ;
50
54
} else {
51
- res . render ( "home" , {
52
- email : req . session . email ,
55
+ res . render ( "dashboard" , {
56
+ posts,
57
+ //pass data into page
53
58
logged_in : true ,
54
59
username : req . session . username ,
55
- title : "Home" ,
60
+ email : req . session . email ,
61
+ // page information
62
+ title : "Dashboard" ,
56
63
} ) ;
57
64
}
58
65
} ) ;
0 commit comments