-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben
committed
Dec 19, 2023
1 parent
339594f
commit 51235e6
Showing
4 changed files
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
"use client"; | ||
import { logout } from "@/services/authService"; | ||
import { useEffect, useState } from "react"; | ||
import { useState } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
function page() { | ||
function Logout() { | ||
const dispatch = useDispatch(); | ||
const [status, setStatus] = useState("Loading..."); | ||
useEffect(() => { | ||
logoutUser(); | ||
async function logoutUser() { | ||
try { | ||
await logout(dispatch).then((res) => { | ||
console.log(res); | ||
setStatus("Logged out"); | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
setStatus("Error logging out"); | ||
throw error; | ||
} | ||
const [status, setStatus] = useState("Press logout below..."); | ||
const handleLogout = async () => { | ||
try { | ||
await logout(dispatch).then((res) => { | ||
console.log(res); | ||
setStatus("Logged out"); | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
setStatus("Error logging out"); | ||
throw error; | ||
} | ||
}, []); | ||
return <div>Current logout status: {status}</div>; | ||
}; | ||
return ( | ||
<div> | ||
{status}{" "} | ||
<button onClick={handleLogout} className="btn btn-primary"> | ||
Logout | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default page; | ||
export default Logout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters