add logout logic, rename functions
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 44s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 44s
This commit is contained in:
parent
a76527d839
commit
6a702c37f1
@ -16,7 +16,7 @@ export default function Login() {
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
const checkStatus = async () => {
|
||||
const validateStageTwo = async () => {
|
||||
setErrorMessage("")
|
||||
setIsLoading(true)
|
||||
|
||||
@ -42,7 +42,7 @@ export default function Login() {
|
||||
}
|
||||
}
|
||||
|
||||
checkStatus()
|
||||
validateStageTwo()
|
||||
}, [magicCode, router])
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
@ -63,7 +63,6 @@ export default function Login() {
|
||||
|
||||
if (response.ok && data.success) {
|
||||
Cookies.set("key", data.key)
|
||||
Cookies.remove("email")
|
||||
Cookies.remove("stageTwoKey")
|
||||
router.push("/account/dashboard")
|
||||
} else {
|
||||
|
@ -3,14 +3,66 @@
|
||||
import { useEffect } from "react"
|
||||
import { Flex, Text, Spinner } from "@radix-ui/themes"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Cookies from "js-cookie"
|
||||
|
||||
export default function Logout() {
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
const verifyKey = async () => {
|
||||
try {
|
||||
const response = await fetch('http://localhost:3001/auth/validateKey', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ email: Cookies.get("email"), key: Cookies.get("key") }),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.error) {
|
||||
router.push('/account/login')
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("There was a problem with checking the existing key:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const logoutUser = async () => {
|
||||
const keycheck = await verifyKey()
|
||||
if (keycheck !== false) {
|
||||
try {
|
||||
const response = await fetch('http://localhost:3001/auth/logout', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ email: Cookies.get("email"), key: Cookies.get("key") }),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success) {
|
||||
Cookies.remove("key")
|
||||
Cookies.remove("email")
|
||||
router.push("/account/login")
|
||||
} else if (data.error) {
|
||||
console.error("There was a problem with processing the logout on the backend:", data.error);
|
||||
} else {
|
||||
console.error("There was a problem with processing the logout on the backend:");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("There was a problem with processing the logout on the backend:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
router.push("/account/login")
|
||||
}, 5000)
|
||||
logoutUser()
|
||||
}, 1250)
|
||||
|
||||
return () => clearTimeout(timer)
|
||||
}, [router])
|
||||
|
Loading…
x
Reference in New Issue
Block a user