개발용도의 쿠키 세팅

This commit is contained in:
nevermoregb 2025-02-13 11:54:38 +09:00
parent e4455e94e5
commit cfa46c0a6d
3 changed files with 29 additions and 25 deletions

5
.env.dev Normal file
View File

@ -0,0 +1,5 @@
VITE_DOMAIN = http://localhost:5173/
# VITE_LOGIN_URL = http://localhost:10325/ms/
# VITE_FILE_URL = http://localhost:10325/ms/
# VITE_API_URL = http://localhost:10325/api/
VITE_API_URL = http://localhost:10325/test/

View File

@ -1,12 +1,12 @@
import axios from "axios"; import axios from 'axios';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useToastStore } from '@s/toastStore'; import { useToastStore } from '@s/toastStore';
const $api = axios.create({ const $api = axios.create({
baseURL: 'http://localhost:10325/api/', baseURL: 'http://localhost:10325/api/',
timeout: 300000, timeout: 300000,
withCredentials : true withCredentials: true,
}) });
/** /**
* Default Content-Type : json * Default Content-Type : json
@ -14,7 +14,6 @@ const $api = axios.create({
*/ */
$api.interceptors.request.use( $api.interceptors.request.use(
function (config) { function (config) {
let contentType = 'application/json'; let contentType = 'application/json';
if (config.isFormData) contentType = 'multipart/form-data'; if (config.isFormData) contentType = 'multipart/form-data';
@ -23,21 +22,21 @@ $api.interceptors.request.use(
config.headers['X-Requested-With'] = 'XMLHttpRequest'; config.headers['X-Requested-With'] = 'XMLHttpRequest';
return config; return config;
}, function (error) { },
function (error) {
// 요청 오류가 있는 작업 수행 // 요청 오류가 있는 작업 수행
return Promise.reject(error); return Promise.reject(error);
} },
); );
// 응답 인터셉터 추가하기 // 응답 인터셉터 추가하기
$api.interceptors.response.use( $api.interceptors.response.use(
function (response) { function (response) {
// 2xx 범위의 응답 처리 // 2xx 범위의 응답 처리
return response; return response;
}, },
function (error) { function (error) {
const toastStore = useToastStore() const toastStore = useToastStore();
const currentPage = error.config.headers['X-Page-Route']; const currentPage = error.config.headers['X-Page-Route'];
// 오류 응답 처리 // 오류 응답 처리
if (error.response) { if (error.response) {
@ -70,7 +69,7 @@ $api.interceptors.response.use(
} }
return Promise.reject(error); return Promise.reject(error);
} },
); );
export default $api; export default $api;

View File

@ -1,14 +1,7 @@
<template> <template>
<form @submit.prevent="handleSubmit"> <form @submit.prevent="handleSubmit">
<div class="col-xl-12"> <div class="col-xl-12">
<UserFormInput <UserFormInput title="아이디" name="id" :is-alert="idAlert" :useInputGroup="true" @update:data="handleIdChange" :value="id" />
title="아이디"
name="id"
:is-alert="idAlert"
:useInputGroup="true"
@update:data="handleIdChange"
:value="id"
/>
<UserFormInput <UserFormInput
title="비밀번호" title="비밀번호"
@ -63,17 +56,24 @@
}; };
const handleSubmit = async () => { const handleSubmit = async () => {
$api.post('user/login', { $api.post(
'user/login',
{
loginId: id.value, loginId: id.value,
password: password.value, password: password.value,
remember: remember.value, remember: remember.value,
}, { headers: { 'X-Page-Route': route.path } }) },
.then(res => { { headers: { 'X-Page-Route': route.path } },
).then(res => {
if (res.status === 200) { if (res.status === 200) {
// TODO:
const sessionCookie = res.data.data;
document.cookie = `JSESSIONID=${sessionCookie};path=/;expires=-1;`;
document.cookie = `JSESSIONID=${sessionCookie};path=/`;
userStore.userInfo(); userStore.userInfo();
router.push('/'); router.push('/');
} }
}) });
}; };
</script> </script>