We can create a route to the post page in the dashboard as a sub-route of the predefined “/users” main route. Doing so, we can mount this sub-route to the “/users” route as “/users/post”. Following the MVC pattern, we can design this “/users/post” route to be linked with methods in the controllers, views, and models folders in order to display a post page in the dashboard. 

 

Moreover, as the “/users/post” route is leading to a forbidden page, and only registered users are allow to get into that area, we need to use the application session to check to see whether the user attempting to get into the dashboard is authenticated or not. If they are authenticated, their user data could be registered in Redis database.

 

// routes/users.ts

import { Router } from "../deps.ts";
const router = Router();


import login from "./users/login.js";
router.use("/", login);

import post from "./users/post.js";
router.use("/post", post);


export default router;

 

// routes/users/post.js

import { Router } from "../../deps.ts";
const router = new Router();

import post from "../../controllers/users/post.js"

router.get("/", (req, res) => {
    if(req.mysession.get("user")){
        post.getPage(req, res);
    }else{ 
        res.redirect("/users");
    }
});


export default router;

 

// controllers/users/post.js


class Post{
    async getPage(req, res){
        const config = req.mysetting();
        config.page_title = "Post Page";
        config.route = "/users/post";

        const html = "Post page";
        res.send(html);
    }
}


export default new Post();

 

GitHub: https://github.com/Sokhavuth/opine-job 

Deno Deploy: https://khmerweb-job.deno.dev/users/post