로그인여부 확인하는 요청

This commit is contained in:
2025-12-29 18:03:43 +09:00
parent e6c532faae
commit 497ac11f26
4 changed files with 33 additions and 4 deletions

View File

@@ -1,9 +1,16 @@
'use client' '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 = () => { const ImgInputForm_client = () => {
//페이지 오픈 시 로그인 여부 확인
useEffect(() => {
isLogin
})
const fileRef = useRef(null) const fileRef = useRef(null)
const [fileName, setFileName] = useState('') const [fileName, setFileName] = useState('')

View File

@@ -1,9 +1,13 @@
'useClient'
import { cookies } from "next/headers" import axios from "axios"
const ImgInputForm_server = () => { const ImgInputForm_server = () => {
console.log('cookies :: ' + cookies.name)
return null
} }
export const isLogin = axios.create({
})
export default ImgInputForm_server export default ImgInputForm_server

6
src/lib/Auth.ts Normal file
View File

@@ -0,0 +1,6 @@
import axios from "axios";
export const callServer = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
withCredentials: true
})

12
src/utils/Login.ts Normal file
View File

@@ -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')
}
})
}