upd: login

Deskripsi:
- upd trycatch fetch wa wibu server di halaman login dan verifikasi kode

No Issues
This commit is contained in:
amel
2024-10-07 13:28:41 +08:00
parent e421b15edd
commit 32176560a6
2 changed files with 41 additions and 30 deletions

View File

@@ -49,9 +49,9 @@ function ViewLogin() {
if (cekLogin.success) { if (cekLogin.success) {
const code = Math.floor(Math.random() * 1000) + 1000 const code = Math.floor(Math.random() * 1000) + 1000
setLoading(true) setLoading(true)
try {
const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then( JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then(
async (res) => { async (res) => {
if (res.status == 200) { if (res.status == 200) {
setValPhone(cekLogin.phone) setValPhone(cekLogin.phone)
@@ -61,11 +61,18 @@ JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masuk
setLoading(false) setLoading(false)
toast.success('Kode verifikasi telah dikirim') toast.success('Kode verifikasi telah dikirim')
} else { } else {
console.error(res.status)
toast.error('Internal Server Error') toast.error('Internal Server Error')
setLoading(false) setLoading(false)
} }
} }
) )
} catch (error) {
console.error(error)
toast.error('Internal Server Error')
}finally{
setLoading(false)
}
} else { } else {
return toast.error(cekLogin.message) return toast.error(cekLogin.message)
} }

View File

@@ -14,10 +14,10 @@ export default function ViewVerification({ phone, otp, user }: IVerification) {
const [isLoading, setLoading] = useState(false) const [isLoading, setLoading] = useState(false)
async function onResend() { async function onResend() {
try {
const code = Math.floor(Math.random() * 1000) + 1000 const code = Math.floor(Math.random() * 1000) + 1000
const res = await fetch(`https://wa.wibudev.com/code?nom=${phone}&text=*DARMASABA*%0A%0A const res = await fetch(`https://wa.wibudev.com/code?nom=${phone}&text=*DARMASABA*%0A%0A
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`) JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`)
.then( .then(
async (res) => { async (res) => {
if (res.status == 200) { if (res.status == 200) {
@@ -28,12 +28,16 @@ JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masuk
} }
} }
); );
} catch (error) {
console.error(error)
toast.error('Internal Server Error')
}
} }
async function getVerification() { async function getVerification() {
setLoading(true) setLoading(true)
if (isOTP == inputOTP) { if (isOTP == inputOTP) {
const setCookies = await funSetCookies({ user: user }) const setCookies: any = await funSetCookies({ user: user })
if (setCookies.success) { if (setCookies.success) {
toast.success(setCookies.message) toast.success(setCookies.message)