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()
|
const router = useRouter()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkStatus = async () => {
|
const validateStageTwo = async () => {
|
||||||
setErrorMessage("")
|
setErrorMessage("")
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkStatus()
|
validateStageTwo()
|
||||||
}, [magicCode, router])
|
}, [magicCode, router])
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
@ -63,7 +63,6 @@ export default function Login() {
|
|||||||
|
|
||||||
if (response.ok && data.success) {
|
if (response.ok && data.success) {
|
||||||
Cookies.set("key", data.key)
|
Cookies.set("key", data.key)
|
||||||
Cookies.remove("email")
|
|
||||||
Cookies.remove("stageTwoKey")
|
Cookies.remove("stageTwoKey")
|
||||||
router.push("/account/dashboard")
|
router.push("/account/dashboard")
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,14 +3,66 @@
|
|||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
import { Flex, Text, Spinner } from "@radix-ui/themes"
|
import { Flex, Text, Spinner } from "@radix-ui/themes"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
|
import Cookies from "js-cookie"
|
||||||
|
|
||||||
export default function Logout() {
|
export default function Logout() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
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")
|
router.push("/account/login")
|
||||||
}, 5000)
|
} 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(() => {
|
||||||
|
logoutUser()
|
||||||
|
}, 1250)
|
||||||
|
|
||||||
return () => clearTimeout(timer)
|
return () => clearTimeout(timer)
|
||||||
}, [router])
|
}, [router])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user