로그인여부 확인하는 요청
This commit is contained in:
@@ -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('')
|
||||
|
||||
@@ -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
|
||||
6
src/lib/Auth.ts
Normal file
6
src/lib/Auth.ts
Normal 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
12
src/utils/Login.ts
Normal 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')
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user