mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
use password from appConfig
This commit is contained in:
parent
0b25ffcdf6
commit
97257e185c
5 changed files with 8 additions and 7 deletions
|
@ -43,7 +43,7 @@ Here is our [Demo Application](https://docs-demo.codex.so/) where you can try Co
|
||||||
git clone https://github.com/codex-team/codex.docs
|
git clone https://github.com/codex-team/codex.docs
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Fill the appConfig
|
### 2. Fill the config
|
||||||
|
|
||||||
Read about available [configuration](https://docs.codex.so/configuration) options.
|
Read about available [configuration](https://docs.codex.so/configuration) options.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
port: 4000
|
port: 4000
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
uploads: "./uploads"
|
uploads: "./uploads"
|
||||||
|
password: secretpassword
|
||||||
frontend:
|
frontend:
|
||||||
title: "CodeX Docs"
|
title: "CodeX Docs"
|
||||||
description: "A block-styled editor with clean JSON output"
|
description: "A block-styled editor with clean JSON output"
|
||||||
|
|
|
@ -22,7 +22,7 @@ router.get('/auth', csrfProtection, function (req: Request, res: Response) {
|
||||||
*/
|
*/
|
||||||
router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Response) => {
|
router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
if (!process.env.PASSWORD) {
|
if (!appConfig.password) {
|
||||||
res.render('auth', {
|
res.render('auth', {
|
||||||
title: 'Login page',
|
title: 'Login page',
|
||||||
header: 'Password not set',
|
header: 'Password not set',
|
||||||
|
@ -32,7 +32,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.password !== process.env.PASSWORD) {
|
if (req.body.password !== appConfig.password) {
|
||||||
res.render('auth', {
|
res.render('auth', {
|
||||||
title: 'Login page',
|
title: 'Login page',
|
||||||
header: 'Wrong password',
|
header: 'Wrong password',
|
||||||
|
@ -46,7 +46,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
||||||
iss: 'Codex Team',
|
iss: 'Codex Team',
|
||||||
sub: 'auth',
|
sub: 'auth',
|
||||||
iat: Date.now(),
|
iat: Date.now(),
|
||||||
}, process.env.PASSWORD + appConfig.auth.secret);
|
}, appConfig.password + appConfig.auth.secret);
|
||||||
|
|
||||||
res.cookie('authToken', token, {
|
res.cookie('authToken', token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
|
|
|
@ -14,14 +14,14 @@ export default async function verifyToken(req: Request, res: Response, next: Nex
|
||||||
const token = req.cookies.authToken;
|
const token = req.cookies.authToken;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!process.env.PASSWORD) {
|
if (!appConfig.password) {
|
||||||
res.locals.isAuthorized = false;
|
res.locals.isAuthorized = false;
|
||||||
next();
|
next();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedToken = jwt.verify(token, process.env.PASSWORD + appConfig.auth.secret);
|
const decodedToken = jwt.verify(token, appConfig.password + appConfig.auth.secret);
|
||||||
|
|
||||||
res.locals.isAuthorized = !!decodedToken;
|
res.locals.isAuthorized = !!decodedToken;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ const AppConfig = z.object({
|
||||||
favicon: z.string().optional(), // Path or URL to favicon
|
favicon: z.string().optional(), // Path or URL to favicon
|
||||||
uploads: z.string(), // Path to uploads folder
|
uploads: z.string(), // Path to uploads folder
|
||||||
hawk: HawkConfig.optional().nullable(), // Hawk configuration
|
hawk: HawkConfig.optional().nullable(), // Hawk configuration
|
||||||
|
password: z.string(), // Password for admin panel
|
||||||
frontend: FrontendConfig, // Frontend configuration
|
frontend: FrontendConfig, // Frontend configuration
|
||||||
auth: AuthConfig, // Auth configuration
|
auth: AuthConfig, // Auth configuration
|
||||||
database: LocalDatabaseConfig, // Database configuration
|
database: LocalDatabaseConfig, // Database configuration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue