2022-01-31 20:47:34 +01:00
|
|
|
import jwt from 'jsonwebtoken'
|
2022-01-15 19:27:18 +01:00
|
|
|
import { Router } from 'express'
|
2022-01-31 20:47:34 +01:00
|
|
|
import AUTH, { SECRET } from './auth.js'
|
2022-01-15 19:27:18 +01:00
|
|
|
|
|
|
|
const ROUTES = Router()
|
|
|
|
|
2022-01-15 20:40:41 +01:00
|
|
|
ROUTES.get('/', (_, res) => res.render("pages/landing.njk"))
|
2022-01-22 21:32:14 +01:00
|
|
|
ROUTES.get('/login', (_, res) => res.render("pages/login.njk"))
|
|
|
|
ROUTES.get('/register', (_, res) => res.render("pages/register.njk"))
|
2022-01-31 20:47:34 +01:00
|
|
|
ROUTES.get(
|
|
|
|
'/manager',
|
|
|
|
(req, res) => {
|
|
|
|
const apiToken = req.signedCookies['api-token'] ?? null
|
|
|
|
if (!apiToken)
|
|
|
|
return res.redirect('/login')
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!jwt.verify(apiToken, SECRET))
|
|
|
|
return res.redirect('/login')
|
|
|
|
|
|
|
|
const bearer = jwt.decode(apiToken)
|
|
|
|
|
|
|
|
res.render('pages/manager.njk', { user: bearer })
|
|
|
|
} catch (error) {
|
|
|
|
res.redirect('/login')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2022-01-15 19:27:18 +01:00
|
|
|
ROUTES.use('/auth', AUTH)
|
|
|
|
|
|
|
|
export default ROUTES
|