fix: login
Deskripsi: - perbaikan loading login - menghapus module yg tak terpakai No Issues
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
import { pwd_key_config } from "@/module/_global";
|
|
||||||
import { funDetectCookies, ViewLogin } from "@/module/auth";
|
import { funDetectCookies, ViewLogin } from "@/module/auth";
|
||||||
import { unsealData } from "iron-session";
|
|
||||||
import _ from "lodash";
|
|
||||||
import { cookies } from "next/headers";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
|
|||||||
@@ -1,28 +1,14 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { LayoutLogin, WARNA } from "@/module/_global";
|
import { LayoutLogin, WARNA } from "@/module/_global";
|
||||||
import {
|
import { Box, Button, Stack, Text, TextInput } from "@mantine/core";
|
||||||
Box,
|
import { useFocusTrap } from "@mantine/hooks";
|
||||||
Button,
|
import { useState } from "react";
|
||||||
Checkbox,
|
|
||||||
Image,
|
|
||||||
rem,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
TextInput,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import React, { useState } from "react";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import ViewVerification from "../../varification/view/view_verification";
|
import ViewVerification from "../../varification/view/view_verification";
|
||||||
import { useFocusTrap } from "@mantine/hooks";
|
|
||||||
|
|
||||||
function ViewLogin() {
|
function ViewLogin() {
|
||||||
const focusTrapRef = useFocusTrap()
|
const focusTrapRef = useFocusTrap()
|
||||||
const router = useRouter()
|
const textInfo = "Kami akan mengirimkan kode verifikasi melalui WhatsApp untuk mengonfirmasi nomor Anda.";
|
||||||
const textInfo =
|
|
||||||
"Kami akan mengirimkan kode verifikasi melalui WhatsApp untuk mengonfirmasi nomor Anda.";
|
|
||||||
|
|
||||||
const [isPhone, setPhone] = useState("")
|
const [isPhone, setPhone] = useState("")
|
||||||
const [isOTP, setOTP] = useState<any>(null)
|
const [isOTP, setOTP] = useState<any>(null)
|
||||||
const [isValPhone, setValPhone] = useState<any>(null)
|
const [isValPhone, setValPhone] = useState<any>(null)
|
||||||
@@ -37,46 +23,50 @@ function ViewLogin() {
|
|||||||
if (isPhone.toString().length <= 11)
|
if (isPhone.toString().length <= 11)
|
||||||
return toast.error('Nomor telepon tidak valid')
|
return toast.error('Nomor telepon tidak valid')
|
||||||
|
|
||||||
const cek = await fetch('/api/auth/login', {
|
try {
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ phone: isPhone })
|
|
||||||
})
|
|
||||||
const cekLogin = await cek.json()
|
|
||||||
|
|
||||||
if (cekLogin.success) {
|
|
||||||
const code = Math.floor(Math.random() * 1000) + 1000
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
const cek = await fetch('/api/auth/login', {
|
||||||
const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A
|
method: 'POST',
|
||||||
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then(
|
headers: {
|
||||||
async (res) => {
|
'Content-Type': 'application/json'
|
||||||
if (res.status == 200) {
|
},
|
||||||
setValPhone(cekLogin.phone)
|
body: JSON.stringify({ phone: isPhone })
|
||||||
setOTP(code)
|
})
|
||||||
setUser(cekLogin.id)
|
const cekLogin = await cek.json()
|
||||||
setVerif(true)
|
if (cekLogin.success) {
|
||||||
setLoading(false)
|
const code = Math.floor(Math.random() * 1000) + 1000
|
||||||
toast.success('Kode verifikasi telah dikirim')
|
try {
|
||||||
} else {
|
const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A
|
||||||
console.error(res.status)
|
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then(
|
||||||
toast.error('Internal Server Error')
|
async (res) => {
|
||||||
setLoading(false)
|
if (res.status == 200) {
|
||||||
|
setValPhone(cekLogin.phone)
|
||||||
|
setOTP(code)
|
||||||
|
setUser(cekLogin.id)
|
||||||
|
setVerif(true)
|
||||||
|
toast.success('Kode verifikasi telah dikirim')
|
||||||
|
} else {
|
||||||
|
console.error(res.status)
|
||||||
|
toast.error('Internal Server Error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
} catch (error) {
|
||||||
} catch (error) {
|
console.error(error)
|
||||||
console.error(error)
|
toast.error('Internal Server Error')
|
||||||
toast.error('Internal Server Error')
|
}
|
||||||
}finally{
|
} else {
|
||||||
setLoading(false)
|
return toast.error(cekLogin.message)
|
||||||
}
|
}
|
||||||
} else {
|
} catch (error) {
|
||||||
return toast.error(cekLogin.message)
|
console.error(error)
|
||||||
|
toast.error('Internal Server Error')
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVerif) return <ViewVerification otp={isOTP} phone={isValPhone} user={isUser} />
|
if (isVerif) return <ViewVerification otp={isOTP} phone={isValPhone} user={isUser} />
|
||||||
|
|||||||
Reference in New Issue
Block a user