feat: add basic auth

This commit is contained in:
Khairul Hidayat 2024-04-13 16:21:01 +07:00
parent e27b047f65
commit ad1ec66e62
2 changed files with 12 additions and 0 deletions

View File

@ -1,2 +1,6 @@
# Static assets/page directory # Static assets/page directory
SERVE_STATIC= SERVE_STATIC=
# Authentication
AUTH_USERNAME=
AUTH_PASSWORD=

View File

@ -1,4 +1,5 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { basicAuth } from "hono/basic-auth";
import HomePage from "../views/pages/home"; import HomePage from "../views/pages/home";
import LinksSection from "../views/sections/links"; import LinksSection from "../views/sections/links";
import db from "../lib/database"; import db from "../lib/database";
@ -7,6 +8,13 @@ import type { Link } from "../types/link";
const router = new Hono(); const router = new Hono();
router.use(
basicAuth({
username: process.env.AUTH_USERNAME || "cebol",
password: process.env.AUTH_PASSWORD || "cebol",
})
);
router.get("/", (c) => { router.get("/", (c) => {
const links = db const links = db
.query("SELECT * FROM links ORDER BY id DESC") .query("SELECT * FROM links ORDER BY id DESC")