260123_ENH : Layout가지 완성된 최초 commit
This commit is contained in:
39
src/app/(pages)/logout/page.tsx
Normal file
39
src/app/(pages)/logout/page.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
'use client'
|
||||
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {useEffect} from "react";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
|
||||
const LogoutPage = () => {
|
||||
const { auth, logout } = useAuth();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const runLogout = async () => {
|
||||
const userId = auth.user?.userId ?? "";
|
||||
logout();
|
||||
|
||||
try {
|
||||
if(userId !== ""){
|
||||
const logoutRequestOptions = {autoLogoutOnAuthError: false};
|
||||
await nextApi.post(`/logout/${userId}`, null, logoutRequestOptions);
|
||||
}
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
}
|
||||
|
||||
router.replace("/login");
|
||||
};
|
||||
|
||||
withLoadingAsync(runLogout);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default LogoutPage;
|
||||
Reference in New Issue
Block a user