From bde21823de7e06340034251901eb64f6909c1011 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 3 Oct 2023 09:32:00 +0800 Subject: [PATCH] title: auto des: auto note:auto --- .env | 2 +- .gitignore | 3 ++- config.yaml | 2 ++ next.config.js | 6 +++++- package.json | 3 ++- src/app/api/auth/register/route.ts | 7 ++++--- src/app/api/auth/validasi/route.ts | 3 ++- src/app/dev/auth/validasi/page.tsx | 4 +++- src/bin/config/index.ts | 11 +++++++++++ yarn.lock | 5 +++++ 10 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 config.yaml create mode 100644 src/bin/config/index.ts diff --git a/.env b/.env index dc4f23c6..e327da6c 100644 --- a/.env +++ b/.env @@ -5,4 +5,4 @@ # See the documentation for all the connection string options: https://pris.ly/d/connection-strings DATABASE_URL="postgresql://bip:Production_123@localhost:5433/hipmi?schema=public" -PWD="QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZ" \ No newline at end of file +PWD="QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZlghvftyguhijknhbgvcfytguu8okjnhbgvfty7u8oilkjnhgvtygu7u8ojilnkhbgvhujnkhghvjhukjnhb" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8f322f0d..786b7c83 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,8 @@ # debug npm-debug.log* -yarn-debug.log* + +rn-debug.log* yarn-error.log* # local env files diff --git a/config.yaml b/config.yaml new file mode 100644 index 00000000..3390da51 --- /dev/null +++ b/config.yaml @@ -0,0 +1,2 @@ +server: + password: QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZlghvftyguhijknhbgvcfytguu8okjnhbgvfty7u8oilkjnhgvtygu7u8ojilnkhbgvhujnkhghvjhukjnhb diff --git a/next.config.js b/next.config.js index 767719fc..983d7350 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + experimental: { + serverActions: true + } +} module.exports = nextConfig diff --git a/package.json b/package.json index 6c44b37b..614f9ed1 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "react-dom": "18.2.0", "react-simple-toasts": "^5.10.0", "tailwindcss": "3.3.3", - "typescript": "5.1.6" + "typescript": "5.1.6", + "yaml": "^2.3.2" } } diff --git a/src/app/api/auth/register/route.ts b/src/app/api/auth/register/route.ts index a8052707..5e825354 100644 --- a/src/app/api/auth/register/route.ts +++ b/src/app/api/auth/register/route.ts @@ -4,8 +4,10 @@ import prisma from "@/app/lib/prisma"; import { data } from "autoprefixer"; import { NextResponse } from "next/server"; import { cookies } from "next/headers"; +import { getConfig } from "@/bin/config"; export async function POST(req: Request) { + if (req.method === "POST") { const body = await req.json(); // MyConsole(body); @@ -35,7 +37,7 @@ export async function POST(req: Request) { username: data.username, }), { - password: process.env.PWD as string, + password: (await getConfig()).server.password, } ); @@ -45,8 +47,7 @@ export async function POST(req: Request) { maxAge: 60 * 60 * 24 * 7, }); - - return NextResponse.json({ status: 201}); + return NextResponse.json({ status: 201 }); } return NextResponse.json({ success: true }); diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index 6879b296..5fc674a6 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -3,6 +3,7 @@ import prisma from "@/app/lib/prisma"; import { NextResponse } from "next/server"; import { cookies } from "next/headers"; import { sealData, unsealData } from "iron-session"; +import {getConfig} from "@/bin/config"; export async function POST(req: Request) { if (req.method === "POST") { @@ -30,7 +31,7 @@ export async function POST(req: Request) { username: data.username, }), { - password: process.env.PWD as string, + password: (await getConfig()).server.password, } ); diff --git a/src/app/dev/auth/validasi/page.tsx b/src/app/dev/auth/validasi/page.tsx index 76eb53ac..9f5a20d0 100644 --- a/src/app/dev/auth/validasi/page.tsx +++ b/src/app/dev/auth/validasi/page.tsx @@ -1,5 +1,7 @@ import { Validasi } from "@/app_modules/auth"; + export default function Page() { - return ; + + return ; } diff --git a/src/bin/config/index.ts b/src/bin/config/index.ts new file mode 100644 index 00000000..3ee540b9 --- /dev/null +++ b/src/bin/config/index.ts @@ -0,0 +1,11 @@ +"use server"; +import yaml from "yaml"; +import fs from "fs"; +import path from "path"; +const config: { server: { password: string } } = yaml.parse( + fs.readFileSync(path.join(__dirname, "./../../../config.yaml")).toString() +); + +export async function getConfig() { + return config; +} diff --git a/yarn.lock b/yarn.lock index 47525054..a2b17237 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3608,6 +3608,11 @@ yaml@^2.1.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== +yaml@^2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.2.tgz#f522db4313c671a0ca963a75670f1c12ea909144" + integrity sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg== + yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"