Deskripsi:
- Create validasi
- Create register
- create global prisma, color tune,dan global state
This commit is contained in:
2023-10-02 22:13:08 +08:00
parent 193dc27e9c
commit cf6aaf500e
32 changed files with 1094 additions and 97 deletions

View File

@@ -0,0 +1,20 @@
import { MyConsole } from "@/app/fun/my_console";
import prisma from "@/app/lib/prisma";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
const body = await req.json();
MyConsole(body);
try {
await fetch(
`https://wa.wibudev.com/code?nom=${body.nomor}&text=${body.otp}`
);
return NextResponse.json({ body, status: 200, message: "Login Success" });
} catch (error) {
return NextResponse.json({ status: 500, message: "Server Error !!!" });
}
}
return NextResponse.json({ success: false });
}

View File

@@ -0,0 +1,12 @@
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function GET() {
cookies().set({
name: "ssn",
value: "",
maxAge: 0,
});
return NextResponse.json({ status: 200, message: "Logout" });
}

View File

@@ -0,0 +1,55 @@
import { sealData } from "iron-session";
import { MyConsole } from "@/app/fun/my_console";
import prisma from "@/app/lib/prisma";
import { data } from "autoprefixer";
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
export async function POST(req: Request) {
if (req.method === "POST") {
const body = await req.json();
// MyConsole(body);
const cekUsername = await prisma.user.findUnique({
where: {
username: body.username,
},
});
MyConsole(cekUsername);
if (cekUsername)
return NextResponse.json({ status: 400, message: "Username sudah ada" });
const data = await prisma.user.create({
data: {
username: body.username,
nomor: body.nomor,
},
});
if (data) {
const seal = await sealData(
JSON.stringify({
id: data.id,
username: data.username,
}),
{
password: process.env.PWD as string,
}
);
cookies().set({
name: "ssn",
value: seal,
maxAge: 60 * 60 * 24 * 7,
});
return NextResponse.json({ status: 201});
}
return NextResponse.json({ success: true });
}
return NextResponse.json({ success: false });
}

View File

@@ -0,0 +1,52 @@
import { MyConsole } from "@/app/fun/my_console";
import prisma from "@/app/lib/prisma";
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import { sealData, unsealData } from "iron-session";
export async function POST(req: Request) {
if (req.method === "POST") {
const body = await req.json();
MyConsole(body);
const data = await prisma.user.findUnique({
where: {
nomor: body.nomor,
},
select: {
id: true,
nomor: true,
username: true,
active: true,
},
});
if (!data) return NextResponse.json({ status: 404 });
if (data) {
const res = await sealData(
JSON.stringify({
id: data.id,
username: data.username,
}),
{
password: process.env.PWD as string,
}
);
const un = await unsealData(res, { password: process.env.PWD as string });
// console.log(JSON.stringify(un), "route validasi")
cookies().set({
name: "ssn",
value: res,
maxAge: 60 * 60 * 24 * 7,
});
return NextResponse.json({ status: 200, data });
}
return NextResponse.json({ success: true });
}
return NextResponse.json({ success: false });
}

View File

@@ -0,0 +1,27 @@
import prisma from "@/app/lib/prisma";
import userRole from "../../../bin/seeder/user_role.json";
import { NextResponse } from "next/server";
export async function GET(req: Request) {
const dev = new URL(req.url).searchParams.get("dev");
if (dev === "DEV-HIPMI") {
for (let i of userRole) {
const data = await prisma.masterUserRole.upsert({
where: {
id: i.id.toString(),
},
update: {
id: i.id.toString(),
name: i.name,
},
create: {
id: i.id.toString(),
name: i.name,
},
});
}
return NextResponse.json({ success: true });
}
return NextResponse.json({ success: false });
}

View File

@@ -0,0 +1,12 @@
import { unsealData } from 'iron-session';
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function GET() {
const c = cookies().get("ssn");
const data = JSON.parse(
await unsealData(c?.value as string, {password: process.env.PWD as string})
)
return NextResponse.json(data);
}

View File

@@ -1,9 +1,14 @@
import { Login } from "@/app_modules/auth";
import { cookies } from "next/headers";
export default function Page() {
const c = cookies().getAll();
const tkn = c;
return (
<>
<Login />
{JSON.stringify(tkn)}
<Login />;
</>
);
}

View File

@@ -0,0 +1,5 @@
import { Register } from "@/app_modules/auth";
export default function Page() {
return <Register />;
}

View File

@@ -1,12 +1,25 @@
import { SplashScreen } from "@/app_modules/auth";
import { useShallowEffect } from "@mantine/hooks";
import { cookies } from "next/headers";
import { useRouter } from "next/navigation";
import { useState } from "react";
import {unsealData} from "iron-session"
export default async function PageSplash() {
const c = cookies().get("ssn");
const tkn = !c
? null
: JSON.parse(
await unsealData(c.value as string, {
password: process.env.PWD as string,
})
);
export default function PageSplash() {
return (
<>
<SplashScreen />
<SplashScreen data={tkn} />
</>
);
}

View File

@@ -0,0 +1,5 @@
import { Validasi } from "@/app_modules/auth";
export default function Page() {
return <Validasi />;
}

View File

@@ -1,8 +1,24 @@
import { HomeView } from "@/app_modules/home";
import { cookies } from "next/headers";
import { unsealData } from "iron-session";
import _ from "lodash";
import { redirect } from "next/navigation";
export default async function Page() {
const c = cookies().get("ssn");
const tkn = !c
? null
: JSON.parse(
await unsealData(c.value as string, {
password: process.env.PWD as string,
})
);
if (!c?.value) return redirect("/dev/auth/login");
export default function Page() {
return (
<>
{/* {JSON.stringify(tkn)} */}
<HomeView />
</>
);

View File

@@ -0,0 +1,8 @@
import { useState } from "react";
export function MyConsole(value: any) {
const onData = true;
if (onData) {
console.log(value);
}
}

View File

@@ -0,0 +1,4 @@
export function randomOTP(){
const random = Math.floor(Math.random() * (9000 - 1000 )) + 1000
return random;
}

9
src/app/lib/api.ts Normal file
View File

@@ -0,0 +1,9 @@
export const ApiHipmi = {
// Get one token
get_token: "/api/user/get-token",
// Auth
login: "/api/auth/login",
validasi: "/api/auth/validasi",
register: "/api/auth/register",
logout: "/api/auth/logout",
};

17
src/app/lib/prisma.ts Normal file
View File

@@ -0,0 +1,17 @@
import { PrismaClient } from '@prisma/client'
const prismaClientSingleton = () => {
return new PrismaClient()
}
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined
}
const prisma = globalForPrisma.prisma ?? prismaClientSingleton()
export default prisma
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma

10
src/app/lib/warna.ts Normal file
View File

@@ -0,0 +1,10 @@
export const Warna = {
hijau_tua: "#297646",
hijau_muda: "#3da18d",
hijau_cerah: "#42c748",
kuning: "#fed630",
biru: "#3175b1",
merah: "#DE2E2D",
hitam: "#121517",
};

View File

@@ -3,5 +3,5 @@ import { redirect } from "next/navigation";
import PageSplash from "./dev/auth/splash/page";
export default async function Page() {
return <PageSplash />;
return <PageSplash/>
}