diff --git a/src/app/components/ImgInputForm.client.tsx b/src/app/components/ImgInputForm.client.tsx index f31feb3..0ec88f8 100644 --- a/src/app/components/ImgInputForm.client.tsx +++ b/src/app/components/ImgInputForm.client.tsx @@ -1,9 +1,16 @@ 'use client' -import { useRef, useState } from "react" +import { useEffect, useRef, useState } from "react" +import { callServer } from "@/lib/Auth" +import { isLogin } from "@/utils/Login" const ImgInputForm_client = () => { + //페이지 오픈 시 로그인 여부 확인 + useEffect(() => { + isLogin + }) + const fileRef = useRef(null) const [fileName, setFileName] = useState('') diff --git a/src/app/components/ImgInputForm.server.tsx b/src/app/components/ImgInputForm.server.tsx index 16cc65c..639473e 100644 --- a/src/app/components/ImgInputForm.server.tsx +++ b/src/app/components/ImgInputForm.server.tsx @@ -1,9 +1,13 @@ +'useClient' -import { cookies } from "next/headers" +import axios from "axios" const ImgInputForm_server = () => { - console.log('cookies :: ' + cookies.name) - return null + } +export const isLogin = axios.create({ + +}) + export default ImgInputForm_server \ No newline at end of file diff --git a/src/lib/Auth.ts b/src/lib/Auth.ts new file mode 100644 index 0000000..382576b --- /dev/null +++ b/src/lib/Auth.ts @@ -0,0 +1,6 @@ +import axios from "axios"; + +export const callServer = axios.create({ + baseURL: process.env.NEXT_PUBLIC_API_URL, + withCredentials: true +}) \ No newline at end of file diff --git a/src/utils/Login.ts b/src/utils/Login.ts new file mode 100644 index 0000000..8f6acdb --- /dev/null +++ b/src/utils/Login.ts @@ -0,0 +1,12 @@ +import { callServer } from "@/lib/Auth"; +import { redirect } from "next/navigation"; + +export async function isLogin() { + const res = callServer.get('/login/get-user-info').then(res => { + const userInfo = res.data + console.log(userInfo) + if (!userInfo) { + redirect('/login') + } + }) +} \ No newline at end of file