"use client"; import { Input } from "@nextui-org/input"; import React, { useState } from "react"; import { EyeFilledIcon, EyeSlashFilledIcon } from "../icons"; import { Button } from "@nextui-org/button"; import Link from "next/link"; import Cookies from "js-cookie"; import { close, error, loading } from "@/config/swal"; import { getProfile, postSignIn } from "@/service/master-user"; import { useRouter } from "next/navigation"; import { HumasLayout } from "../layout/humas-layout"; import { Checkbox } from "@nextui-org/react"; export default function Login() { const router = useRouter(); const [isVisible, setIsVisible] = React.useState(false); const toggleVisibility = () => setIsVisible(!isVisible); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const onSubmit = async () => { const data = { username: username, password: password, }; if (!username || !password) { error("Username & Password Wajib Diisi !"); } else { loading(); const response = await postSignIn(data); if (response?.error) { error("Username / Password Tidak Sesuai"); } else { const access_token: any = response?.data?.data?.id_token; const refresh_token: any = response?.data?.data?.refresh_token; const dateTime: any = new Date(); const newTime: any = dateTime.getTime() + 10 * 60 * 1000; Cookies.set("access_token", access_token, { expires: 1, }); Cookies.set("refresh_token", refresh_token, { expires: 1, }); Cookies.set("time_refresh", newTime, { expires: 1, }); Cookies.set("is_first_login", "true", { secure: true, sameSite: "strict", }); const profile = await getProfile(); console.log("PROFILE : ", profile?.data); Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { expires: 1, }); Cookies.set("uie", profile?.data?.data?.id, { expires: 1, }); Cookies.set("ufne", profile?.data?.data?.fullname, { expires: 1, }); Cookies.set("username", profile?.data?.data?.username, { expires: 1, }); Cookies.set("urie", profile?.data?.data?.roleId, { expires: 1, }); Cookies.set("roleName", profile?.data?.data?.roleName, { expires: 1, }); Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { expires: 1, }); Cookies.set("ulne", profile?.data?.data?.roleLevelNumber, { expires: 1, }); Cookies.set("urce", profile?.data?.data?.roleCode, { expires: 1, }); Cookies.set("email", profile?.data?.data?.email, { expires: 1, }); close(); router.push("/admin/dashboard"); Cookies.set("status", "login", { expires: 1, }); } } // } }; const setValUsername = (e: any) => { const uname = e.replaceAll(/[^\w.-]/g, ""); setUsername(uname.toLowerCase()); }; return ( // //
//
//
// Selamat Datang di Portal Resmi Humas Polri //
//
// { // setValUsername(e.target.value.trim()); // }} // onPaste={(e: any) => { // setValUsername(e.target.value.trim()); // }} // onCopy={(e: any) => { // setValUsername(e.target.value.trim()); // }} // /> //
//
// // {isVisible ? ( // // ) : ( // // )} // // } // type={isVisible ? "text" : "password"} // label="Password" // placeholder="Masukkan password anda" // variant="underlined" // onChange={(event) => setPassword(event.target.value)} // /> //
//
// //
//
// Don't have account? Register Now //
//
// // // //
//
//
// logo //
//
//

Login

Username

{ setValUsername(e.target.value.trim()); }} onPaste={(e: any) => { setValUsername(e.target.value.trim()); }} onCopy={(e: any) => { setValUsername(e.target.value.trim()); }} />

Password

{isVisible ? ( ) : ( )} } type={isVisible ? "text" : "password"} label="" placeholder="" onChange={(event) => setPassword(event.target.value)} />
Remember me
Reset Password
Don't have accout yet?{" "} New Account
); }