Skip to content

Commit 3f60b18

Browse files
authored
Merge pull request #187 from TaskFlow-CLAP/CLAP-423
CLAP-423 초기 비밀번호 재설정 불가능 오류 수정
2 parents 1f5b1dd + 553c6ba commit 3f60b18

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

src/api/auth.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ export const postLogin = async (nickName: string, password: string) => {
2525
path: '/',
2626
sameSite: 'strict'
2727
})
28-
Cookies.set('refreshToken', response.data.refreshToken, {
29-
path: '/',
30-
sameSite: 'strict'
31-
})
28+
if (response.data.refreshToken) {
29+
Cookies.set('refreshToken', response.data.refreshToken, {
30+
path: '/',
31+
sameSite: 'strict'
32+
})
33+
}
3234
return response.data
3335
}
3436

3537
export const patchPassword = async (password: string) => {
3638
const request = { password }
37-
const response = await axiosInstance.patch('/api/members/password', request)
38-
return response.data
39+
const refreshToken = Cookies.get('refreshToken')
40+
if (refreshToken) {
41+
const response = await axiosInstance.patch('/api/members/password', request)
42+
return response.data
43+
} else {
44+
const response = await axiosInstance.patch('/api/members/initial-password', request)
45+
return response.data
46+
}
3947
}
4048

4149
export const deleteLogout = async () => {

src/constants/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const COLOR_LIST = [
4040
]
4141

4242
export const PERMITTED_URL = {
43-
UNKNOWN: ['/login', '/pw-change-email'],
43+
UNKNOWN: ['/login', '/pw-change-email', '/pw-change'],
4444
ROLE_USER: ['/my-request', '/task-request', '/edit-information', '/pw-change'],
4545
ROLE_MANAGER: [
4646
'/my-task',

src/router/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ router.beforeEach(async (to, from, next) => {
143143
ROLE_ADMIN: '/member-management'
144144
}
145145

146-
if ((info.role && PERMITTED_URL.UNKNOWN.includes(to.path)) || (info.role && to.path === '/')) {
146+
if (
147+
(info.role && PERMITTED_URL.UNKNOWN.includes(to.path) && to.path !== '/pw-change') ||
148+
(info.role && to.path === '/')
149+
) {
147150
return next(redirectMap[info.role])
148151
}
149152

@@ -167,11 +170,20 @@ router.beforeEach(async (to, from, next) => {
167170
ROLE_ADMIN: PERMITTED_URL.ROLE_ADMIN
168171
}
169172

170-
if (from.path === redirectMap[info.role] && !permittedUrlMap[info.role].includes(to.path)) {
173+
const isPathPermitted = (path: string, permittedPaths: string[]) => {
174+
return permittedPaths.some(permittedPath => {
175+
return path.startsWith(permittedPath)
176+
})
177+
}
178+
179+
if (
180+
from.path === redirectMap[info.role] &&
181+
!isPathPermitted(to.path, permittedUrlMap[info.role])
182+
) {
171183
return false
172184
}
173185

174-
if (!permittedUrlMap[info.role].includes(to.path)) {
186+
if (!isPathPermitted(to.path, permittedUrlMap[info.role])) {
175187
if (to.path === redirectMap[info.role]) {
176188
return next()
177189
}

src/stores/member.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const useMemberStore = defineStore('memberInfo', () => {
2626

2727
async function updateMemberInfoWithToken() {
2828
const token = Cookies.get('accessToken')
29-
if (!token) return
29+
const refreshToken = Cookies.get('refreshToken')
30+
if (!token || !refreshToken) return
3031

3132
const { data }: { data: User } = await axiosInstance.get('/api/members/info')
3233
info.value = data

src/views/LoginView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const handleLogin = async () => {
8484
8585
if (!Cookies.get('refreshToken')) {
8686
router.push('/pw-change')
87-
} else if (res && role && Cookies.get('refreshToken')) {
87+
} else if (res) {
8888
switch (role) {
8989
case 'ROLE_ADMIN':
9090
router.push('/member-management')

src/views/PwChangeView.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
v-model="pw"
3434
placeholder="비밀번호를 입력해주세요"
3535
required
36-
class="input-box" />
36+
class="input-box"
37+
autocomplete="current-password" />
3738
<div class="flex flex-col gap-2">
3839
<button
3940
type="submit"
@@ -60,6 +61,7 @@
6061
placeholder="새 비밀번호를 입력해주세요"
6162
required
6263
ref="passwordInput"
64+
autocomplete="new-password"
6365
:class="[
6466
'block w-full px-4 py-4 border rounded focus:outline-none',
6567
isInvalid ? 'border-red-1' : 'border-border-1'
@@ -78,6 +80,7 @@
7880
ref="checkPwInput"
7981
placeholder="새 비밀번호를 다시 입력해주세요"
8082
required
83+
autocomplete="new-password"
8184
:class="[
8285
'block w-full px-4 py-4 border rounded focus:outline-none',
8386
isDifferent ? 'border-red-1' : 'border-border-1'
@@ -108,9 +111,10 @@
108111
<script setup lang="ts">
109112
import { patchPassword, postPasswordCheck } from '@/api/auth'
110113
import TitleContainer from '@/components/common/TitleContainer.vue'
111-
import { nextTick, ref } from 'vue'
114+
import { nextTick, onMounted, ref } from 'vue'
112115
import ModalView from '@/components/common/ModalView.vue'
113116
import { useRouter } from 'vue-router'
117+
import Cookies from 'js-cookie'
114118
115119
const isErrorVisible = ref(false)
116120
@@ -134,6 +138,13 @@ const passwordInput = ref<HTMLInputElement | null>(null)
134138
const isModalVisible = ref(false)
135139
const router = useRouter()
136140
141+
onMounted(() => {
142+
const refreshToken = Cookies.get('refreshToken')
143+
if (!refreshToken) {
144+
isConfirmed.value = true
145+
}
146+
})
147+
137148
const validatePassword = () => {
138149
const regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+{}\[\]:;<>,.?/~`-]).{8,20}$/
139150
isInvalid.value = !regex.test(newPw.value)
@@ -165,7 +176,12 @@ const handleChange = async () => {
165176
166177
const closeModal = () => {
167178
isModalVisible.value = !isModalVisible.value
168-
router.replace('/edit-information')
179+
if (Cookies.get('refreshToken')) {
180+
router.replace('/edit-information')
181+
} else {
182+
Cookies.remove('accessToken')
183+
router.replace('/login')
184+
}
169185
}
170186
const closeError = () => {
171187
isErrorVisible.value = !isErrorVisible.value

0 commit comments

Comments
 (0)