diff --git a/src/api/auth.ts b/src/api/auth.ts index 35cb139..6ea94ad 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -25,17 +25,25 @@ export const postLogin = async (nickName: string, password: string) => { path: '/', sameSite: 'strict' }) - Cookies.set('refreshToken', response.data.refreshToken, { - path: '/', - sameSite: 'strict' - }) + if (response.data.refreshToken) { + Cookies.set('refreshToken', response.data.refreshToken, { + path: '/', + sameSite: 'strict' + }) + } return response.data } export const patchPassword = async (password: string) => { const request = { password } - const response = await axiosInstance.patch('/api/members/password', request) - return response.data + const refreshToken = Cookies.get('refreshToken') + if (refreshToken) { + const response = await axiosInstance.patch('/api/members/password', request) + return response.data + } else { + const response = await axiosInstance.patch('/api/members/initial-password', request) + return response.data + } } export const deleteLogout = async () => { diff --git a/src/constants/common.ts b/src/constants/common.ts index f459a61..669c53c 100644 --- a/src/constants/common.ts +++ b/src/constants/common.ts @@ -40,7 +40,7 @@ export const COLOR_LIST = [ ] export const PERMITTED_URL = { - UNKNOWN: ['/login', '/pw-change-email'], + UNKNOWN: ['/login', '/pw-change-email', '/pw-change'], ROLE_USER: ['/my-request', '/task-request', '/edit-information', '/pw-change'], ROLE_MANAGER: [ '/my-task', diff --git a/src/router/index.ts b/src/router/index.ts index b4d4601..2aea2b9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -143,7 +143,10 @@ router.beforeEach(async (to, from, next) => { ROLE_ADMIN: '/member-management' } - if ((info.role && PERMITTED_URL.UNKNOWN.includes(to.path)) || (info.role && to.path === '/')) { + if ( + (info.role && PERMITTED_URL.UNKNOWN.includes(to.path) && to.path !== '/pw-change') || + (info.role && to.path === '/') + ) { return next(redirectMap[info.role]) } @@ -167,11 +170,20 @@ router.beforeEach(async (to, from, next) => { ROLE_ADMIN: PERMITTED_URL.ROLE_ADMIN } - if (from.path === redirectMap[info.role] && !permittedUrlMap[info.role].includes(to.path)) { + const isPathPermitted = (path: string, permittedPaths: string[]) => { + return permittedPaths.some(permittedPath => { + return path.startsWith(permittedPath) + }) + } + + if ( + from.path === redirectMap[info.role] && + !isPathPermitted(to.path, permittedUrlMap[info.role]) + ) { return false } - if (!permittedUrlMap[info.role].includes(to.path)) { + if (!isPathPermitted(to.path, permittedUrlMap[info.role])) { if (to.path === redirectMap[info.role]) { return next() } diff --git a/src/stores/member.ts b/src/stores/member.ts index 0c20716..88bb4c3 100644 --- a/src/stores/member.ts +++ b/src/stores/member.ts @@ -26,7 +26,8 @@ export const useMemberStore = defineStore('memberInfo', () => { async function updateMemberInfoWithToken() { const token = Cookies.get('accessToken') - if (!token) return + const refreshToken = Cookies.get('refreshToken') + if (!token || !refreshToken) return const { data }: { data: User } = await axiosInstance.get('/api/members/info') info.value = data diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index d029cd9..1a1ad98 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -84,7 +84,7 @@ const handleLogin = async () => { if (!Cookies.get('refreshToken')) { router.push('/pw-change') - } else if (res && role && Cookies.get('refreshToken')) { + } else if (res) { switch (role) { case 'ROLE_ADMIN': router.push('/member-management') diff --git a/src/views/PwChangeView.vue b/src/views/PwChangeView.vue index 18a60cf..ebfdae6 100644 --- a/src/views/PwChangeView.vue +++ b/src/views/PwChangeView.vue @@ -33,7 +33,8 @@ v-model="pw" placeholder="비밀번호를 입력해주세요" required - class="input-box" /> + class="input-box" + autocomplete="current-password" />