upd: logout

This commit is contained in:
amel
2024-07-30 15:59:20 +08:00
parent 2e8d2b3c1f
commit d0166cb2a3
2 changed files with 16 additions and 12 deletions

View File

@@ -38,8 +38,7 @@ export default function ViewVerification({ phone, otp, user }: IVerification) {
toast.success(setCookies.message) toast.success(setCookies.message)
if (setCookies.pertamaLogin == true) if (setCookies.pertamaLogin == true)
return router.replace('/welcome') return router.replace('/welcome')
console.log(setCookies.pertamaLogin) return window.location.href = '/home';
return router.replace('/home')
} else { } else {
toast.error(setCookies.message) toast.error(setCookies.message)
} }

View File

@@ -16,13 +16,18 @@ import { useState } from "react";
export default function ViewProfile() { export default function ViewProfile() {
const [openModal, setOpenModal] = useState(false); const [openModal, setOpenModal] = useState(false);
async function onLogout() { async function onLogout(val: boolean) {
try { try {
await fetch('/api/auth/logout', { if (val) {
method: 'DELETE', await fetch('/api/auth/logout', {
}); method: 'DELETE',
toast.success('Logout Success') });
window.location.href = '/'; toast.success('Logout Success')
window.location.href = '/';
}
setOpenModal(false)
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@@ -33,9 +38,9 @@ export default function ViewProfile() {
<Group justify="space-between"> <Group justify="space-between">
<LayoutIconBack /> <LayoutIconBack />
<ActionIcon onClick={() => { setOpenModal(true) }} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Info"> <ActionIcon onClick={() => { setOpenModal(true) }} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Info">
<LuLogOut size={20} color='white' /> <LuLogOut size={20} color='white' />
</ActionIcon> </ActionIcon>
</Group> </Group>
<Stack <Stack
align="center" align="center"
@@ -82,7 +87,7 @@ export default function ViewProfile() {
<LayoutModal opened={openModal} onClose={() => setOpenModal(false)} <LayoutModal opened={openModal} onClose={() => setOpenModal(false)}
description="Apakah Anda yakin ingin Keluar?" description="Apakah Anda yakin ingin Keluar?"
onYes={() => onLogout()} /> onYes={(val) => onLogout(val)} />
</> </>
) )
} }