Login bug fix
This commit is contained in:
@@ -6,29 +6,6 @@ import { randomOTP } from "./rondom_otp";
|
||||
export async function auth_funLogin(nomor: string) {
|
||||
const codeOtp = randomOTP();
|
||||
|
||||
// const res = await fetch(
|
||||
// `https://wa.wibudev.com/code?nom=${nomor}&text=Masukan Kode OTP:${codeOtp}`
|
||||
// );
|
||||
|
||||
// const sendWa = await res.json();
|
||||
// if (sendWa.status !== "success")
|
||||
// return { status: 400, message: "WA Tidak Terdaftar" };
|
||||
|
||||
// const createOtpId = await prisma.kodeOtp.create({
|
||||
// data: {
|
||||
// nomor: nomor,
|
||||
// otp: codeOtp,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!createOtpId) return { status: 400, message: "Gagal Membuat Kode OTP" };
|
||||
|
||||
// return {
|
||||
// status: 200,
|
||||
// message: "Kode Verifikasi Dikirim",
|
||||
// kodeOtpId: createOtpId.id
|
||||
// };
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://wa.wibudev.com/code?nom=${nomor}&text=Masukan Kode OTP:${codeOtp}`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function auth_Logout(kodeId: string) {
|
||||
@@ -8,6 +9,7 @@ export async function auth_Logout(kodeId: string) {
|
||||
name: "ssn",
|
||||
value: "",
|
||||
maxAge: 0,
|
||||
path: "/dev/auth/login",
|
||||
});
|
||||
|
||||
const c = cookies().get("ssn");
|
||||
@@ -19,7 +21,7 @@ export async function auth_Logout(kodeId: string) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal Hapus Kode OTP Id" };
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal Hapus Kode OTP Id"};
|
||||
revalidatePath("/dev/katalog")
|
||||
return { status: 200, message: "Logout Berhasil" };
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ export async function Auth_funRegister(data: any) {
|
||||
|
||||
const seal = await sealData(
|
||||
JSON.stringify({
|
||||
id: data.id,
|
||||
username: data.username,
|
||||
id: create.id,
|
||||
username: create.username,
|
||||
}),
|
||||
{
|
||||
password: await config.server.password,
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||
import { ApiHipmi } from "@/app/lib/api";
|
||||
import { Warna } from "@/app/lib/warna";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Flex,
|
||||
@@ -16,33 +13,34 @@ import {
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { getHotkeyHandler, useFocusTrap, useHotkeys } from "@mantine/hooks";
|
||||
import { useFocusTrap } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { gs_otp, gs_nomor, gs_kodeId } from "../state/state";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { NotifBerhasil } from "@/app_modules/donasi/component/notifikasi/notif_berhasil";
|
||||
import { NotifGagal } from "@/app_modules/donasi/component/notifikasi/notif_gagal";
|
||||
import { gs_kodeId } from "../state/state";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan";
|
||||
import { auth_funLogin } from "@/app_modules/auth/fun/fun_login";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
|
||||
import { PhoneInput } from "react-international-phone";
|
||||
import "react-international-phone/style.css";
|
||||
|
||||
export default function Login() {
|
||||
const router = useRouter();
|
||||
const [nomor, setNomor] = useState("");
|
||||
const [kodeId, setKodeId] = useAtom(gs_kodeId);
|
||||
const focusTrapRef = useFocusTrap();
|
||||
const [phone, setPhone] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onLogin() {
|
||||
if (nomor.length < 10)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Nomor minimal 10 digit");
|
||||
if (nomor.length > 13)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Nomor maximal 13 digit");
|
||||
// if (nomor.length < 10)
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Nomor minimal 10 digit");
|
||||
// if (nomor.length > 13)
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Nomor maximal 13 digit");
|
||||
|
||||
const nomorHp = phone.substring(1);
|
||||
|
||||
await auth_funLogin(nomor).then((res) => {
|
||||
await auth_funLogin(nomorHp).then((res) => {
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setKodeId(res.kodeOtpId);
|
||||
@@ -79,7 +77,6 @@ export default function Login() {
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<Center h={"80%"}>
|
||||
<Stack px={"lg"} spacing={"xl"} w={{ base: 400 }} justify="center">
|
||||
<Center h={"100%"}>
|
||||
@@ -98,7 +95,7 @@ export default function Login() {
|
||||
</Text>
|
||||
</Stack>
|
||||
|
||||
<Grid>
|
||||
{/* <Grid>
|
||||
<Grid.Col span={"content"}>
|
||||
<Center h={"100%"}>
|
||||
<Text fw={"bold"}>+62</Text>
|
||||
@@ -115,7 +112,16 @@ export default function Login() {
|
||||
}}
|
||||
/>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Grid> */}
|
||||
|
||||
<PhoneInput
|
||||
// ref={focusTrapRef}
|
||||
inputStyle={{ width: "100%" }}
|
||||
defaultCountry="id"
|
||||
onChange={(val) => {
|
||||
setPhone(val);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
radius={"md"}
|
||||
@@ -124,7 +130,10 @@ export default function Login() {
|
||||
color={"teal"}
|
||||
onClick={() => {
|
||||
onLogin();
|
||||
setLoading(true);
|
||||
}}
|
||||
loading={loading ? true : false}
|
||||
loaderPosition="center"
|
||||
>
|
||||
<Text>LOGIN</Text>
|
||||
</Button>
|
||||
|
||||
@@ -10,11 +10,15 @@ import { useDisclosure } from "@mantine/hooks";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
|
||||
import { auth_Logout } from "../fun/fun_logout";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function User_Logout() {
|
||||
const router = useRouter();
|
||||
const [opened, { toggle }] = useDisclosure(false);
|
||||
const [kodeId, setKodeId] = useAtom(gs_kodeId);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loading2, setLoading2] = useState(false);
|
||||
|
||||
const onLogout = async () => {
|
||||
// await fetch(ApiHipmi.logout)
|
||||
@@ -34,6 +38,7 @@ export default function User_Logout() {
|
||||
if (res.status === 200) {
|
||||
setKodeId("");
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterAuth.login)
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
@@ -46,15 +51,25 @@ export default function User_Logout() {
|
||||
<Stack>
|
||||
<Title order={6}>Anda yakin ingin keluar ?</Title>
|
||||
<Group align="center" position="center">
|
||||
<Button compact onClick={toggle} radius={50}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setLoading(false);
|
||||
toggle();
|
||||
}}
|
||||
radius={50}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
compact
|
||||
loaderPosition="center"
|
||||
loading={loading2 ? true : false}
|
||||
radius={50}
|
||||
bg={Warna.merah}
|
||||
color="red"
|
||||
onClick={() => onClickLogout()}
|
||||
onClick={() => {
|
||||
setLoading2(true);
|
||||
onClickLogout();
|
||||
}}
|
||||
>
|
||||
Keluar
|
||||
</Button>
|
||||
@@ -64,7 +79,16 @@ export default function User_Logout() {
|
||||
{/* <ActionIcon variant="transparent">
|
||||
<IconLogout color={Warna.merah} onClick={toggle} />
|
||||
</ActionIcon> */}
|
||||
<Button radius={"xl"} color={"red"} onClick={toggle}>
|
||||
<Button
|
||||
loading={loading ? true : false}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
color={"red"}
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
toggle();
|
||||
}}
|
||||
>
|
||||
Logout
|
||||
</Button>
|
||||
</>
|
||||
|
||||
@@ -33,6 +33,7 @@ export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
const [nomor, setNomor] = useState(dataOtp.nomor);
|
||||
const [value, setValue] = useState("");
|
||||
const focusTrapRef = useFocusTrap();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// const onRegister = async () => {
|
||||
// myConsole(value);
|
||||
@@ -169,12 +170,15 @@ export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
|
||||
<Stack>
|
||||
<Button
|
||||
loading={loading ? true : false}
|
||||
loaderPosition="center"
|
||||
radius={"md"}
|
||||
compact
|
||||
h={40}
|
||||
color={"teal"}
|
||||
onClick={() => {
|
||||
onRegistarsi();
|
||||
setLoading(true);
|
||||
}}
|
||||
>
|
||||
<Text>DAFTAR</Text>
|
||||
|
||||
@@ -42,6 +42,7 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
const [code, setCode] = useState(dataOtp.otp);
|
||||
const [inputCode, setInputOtp] = useState("");
|
||||
const focusTrapRef = useFocusTrap();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const onValid = async () => {
|
||||
// MyConsole(inputCode)
|
||||
@@ -174,12 +175,15 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
</Center>
|
||||
<Stack>
|
||||
<Button
|
||||
loading={loading ? true : false}
|
||||
loaderPosition="center"
|
||||
radius={"md"}
|
||||
compact
|
||||
h={40}
|
||||
color={"teal"}
|
||||
onClick={() => {
|
||||
onVerifikasi();
|
||||
setLoading(true)
|
||||
}}
|
||||
>
|
||||
<Text>VERIFIKASI</Text>
|
||||
|
||||
Reference in New Issue
Block a user