f34980048b
- 계정정보: 아이디·가입유형 행 제거 (이름/이메일/권한만), '이름 변경' 버튼 - ProfileEdit: 소셜(구글) 계정은 비밀번호 재인증 없이 바로 이름만 변경 (아이디/이메일 편집/비밀번호 변경 섹션은 LOCAL 전용으로 숨김) - 백엔드 updateProfile 은 provider 무관하게 동작(변경 없음) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
287 lines
8.0 KiB
Vue
287 lines
8.0 KiB
Vue
<script setup>
|
|
import { computed, reactive, ref, onMounted } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import { authApi } from '@/api/authApi'
|
|
|
|
const auth = useAuthStore()
|
|
const router = useRouter()
|
|
|
|
// 소셜(구글 등) 계정은 비밀번호가 없어 재인증 없이 이름만 변경
|
|
const isSocial = computed(() => (auth.user?.provider || 'LOCAL') !== 'LOCAL')
|
|
|
|
const step = ref('verify') // 'verify' → 'edit' (소셜은 곧바로 edit)
|
|
const password = ref('') // verify 단계에서 입력한 현재 비밀번호 (비밀번호 변경 시 재사용)
|
|
const form = reactive({ name: '', email: '' })
|
|
const pw = reactive({ next: '', confirm: '' }) // 비밀번호 변경(선택, LOCAL 전용)
|
|
const loading = ref(false)
|
|
const error = ref('')
|
|
|
|
onMounted(() => {
|
|
// 소셜 계정: 비밀번호 인증 단계 건너뛰고 바로 이름 변경 화면으로
|
|
if (isSocial.value) {
|
|
form.name = auth.user?.name || ''
|
|
form.email = auth.user?.email || ''
|
|
step.value = 'edit'
|
|
}
|
|
})
|
|
|
|
async function verify() {
|
|
error.value = ''
|
|
if (!password.value) {
|
|
error.value = '비밀번호를 입력하세요.'
|
|
return
|
|
}
|
|
loading.value = true
|
|
try {
|
|
await authApi.verifyPassword(password.value)
|
|
// 인증 통과 → 현재 값으로 폼 채우고 변경 화면 진입
|
|
form.name = auth.user?.name || ''
|
|
form.email = auth.user?.email || ''
|
|
step.value = 'edit'
|
|
} catch (e) {
|
|
error.value = e.response?.data?.message || '비밀번호 인증에 실패했습니다.'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function save() {
|
|
error.value = ''
|
|
const name = form.name.trim()
|
|
if (!name) {
|
|
error.value = '이름을 입력하세요.'
|
|
return
|
|
}
|
|
// 소셜 계정은 이메일(구글 제공) 유지, LOCAL 만 폼에서 편집
|
|
const email = isSocial.value ? (auth.user?.email || null) : (form.email.trim() || null)
|
|
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
error.value = '이메일 형식이 올바르지 않습니다.'
|
|
return
|
|
}
|
|
// 비밀번호 변경(선택, LOCAL 전용) — 새 비밀번호를 입력한 경우에만 검증/적용
|
|
const changePw = !isSocial.value && !!pw.next
|
|
if (changePw) {
|
|
if (pw.next.length < 8 || pw.next.length > 64) {
|
|
error.value = '새 비밀번호는 8~64자여야 합니다.'
|
|
return
|
|
}
|
|
if (pw.next !== pw.confirm) {
|
|
error.value = '새 비밀번호 확인이 일치하지 않습니다.'
|
|
return
|
|
}
|
|
if (pw.next === password.value) {
|
|
error.value = '새 비밀번호가 현재 비밀번호와 동일합니다.'
|
|
return
|
|
}
|
|
}
|
|
loading.value = true
|
|
try {
|
|
const res = await authApi.updateProfile({ name, email: email || null })
|
|
await auth.applyUser({ name: res.name, email: res.email })
|
|
// verify 단계에서 입력한 현재 비밀번호를 그대로 사용해 비밀번호도 변경
|
|
if (changePw) {
|
|
await authApi.changePassword({ currentPassword: password.value, newPassword: pw.next })
|
|
}
|
|
window.alert(changePw ? '가입정보와 비밀번호가 변경되었습니다.' : '가입정보가 변경되었습니다.')
|
|
router.push('/settings/account')
|
|
} catch (e) {
|
|
error.value = e.response?.data?.message || '변경에 실패했습니다.'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function cancel() {
|
|
router.push('/settings/account')
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="profile-edit">
|
|
|
|
<!-- 1단계: 비밀번호 재인증 -->
|
|
<form v-if="step === 'verify'" class="card form" @submit.prevent="verify">
|
|
<p class="guide">본인 확인을 위해 비밀번호를 입력하세요.</p>
|
|
<label class="field">
|
|
<span class="flabel">비밀번호</span>
|
|
<input
|
|
v-model="password" type="password" autocomplete="current-password"
|
|
placeholder="현재 비밀번호" :disabled="loading"
|
|
/>
|
|
</label>
|
|
<p v-if="error" class="error">{{ error }}</p>
|
|
<button class="primary-btn" type="submit" :disabled="loading">
|
|
{{ loading ? '확인 중…' : '확인' }}
|
|
</button>
|
|
</form>
|
|
|
|
<!-- 2단계: 가입정보 변경 -->
|
|
<form v-else class="card form" @submit.prevent="save">
|
|
<label v-if="!isSocial" class="field">
|
|
<span class="flabel">아이디</span>
|
|
<input :value="auth.user?.loginId" type="text" disabled />
|
|
<span class="fnote">아이디는 변경할 수 없습니다.</span>
|
|
</label>
|
|
<label class="field">
|
|
<span class="flabel">이름</span>
|
|
<input v-model="form.name" type="text" maxlength="100" placeholder="이름" :disabled="loading" />
|
|
</label>
|
|
<label v-if="!isSocial" class="field">
|
|
<span class="flabel">이메일</span>
|
|
<input v-model="form.email" type="email" maxlength="255" placeholder="이메일 (선택)" :disabled="loading" />
|
|
</label>
|
|
|
|
<template v-if="!isSocial">
|
|
<hr class="divider" />
|
|
<p class="section-label">비밀번호 변경 <span class="opt">(변경 시에만 입력)</span></p>
|
|
<label class="field">
|
|
<span class="flabel">새 비밀번호</span>
|
|
<input v-model="pw.next" type="password" autocomplete="new-password" maxlength="64" placeholder="새 비밀번호 (8~64자)" :disabled="loading" />
|
|
</label>
|
|
<label class="field">
|
|
<span class="flabel">새 비밀번호 확인</span>
|
|
<input v-model="pw.confirm" type="password" autocomplete="new-password" maxlength="64" placeholder="새 비밀번호 확인" :disabled="loading" />
|
|
</label>
|
|
</template>
|
|
|
|
<p v-if="error" class="error">{{ error }}</p>
|
|
<div class="actions">
|
|
<button class="ghost-btn" type="button" :disabled="loading" @click="cancel">취소</button>
|
|
<button class="primary-btn" type="submit" :disabled="loading">
|
|
{{ loading ? '저장 중…' : '저장' }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.profile-edit {
|
|
max-width: 560px;
|
|
margin: 0 auto;
|
|
}
|
|
.back {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.3rem;
|
|
margin-bottom: 0.75rem;
|
|
padding: 0.3rem 0.1rem;
|
|
border: 0;
|
|
background: transparent;
|
|
color: var(--color-text);
|
|
opacity: 0.75;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
}
|
|
.back:hover {
|
|
opacity: 1;
|
|
}
|
|
.back svg {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
.page-title {
|
|
font-size: 1.4rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.card {
|
|
background: var(--color-background-soft);
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 10px;
|
|
padding: 1.25rem 1.1rem;
|
|
}
|
|
.form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
.guide {
|
|
font-size: 0.88rem;
|
|
opacity: 0.7;
|
|
margin: 0;
|
|
}
|
|
.field {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.35rem;
|
|
}
|
|
.flabel {
|
|
font-size: 0.82rem;
|
|
opacity: 0.7;
|
|
}
|
|
.field input {
|
|
padding: 0.65rem 0.75rem;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 6px;
|
|
background: var(--color-background);
|
|
color: var(--color-text);
|
|
font-size: 0.95rem;
|
|
}
|
|
.field input:disabled {
|
|
opacity: 0.6;
|
|
}
|
|
.fnote {
|
|
font-size: 0.74rem;
|
|
opacity: 0.5;
|
|
}
|
|
.divider {
|
|
border: 0;
|
|
border-top: 1px solid var(--color-border);
|
|
margin: 0.25rem 0;
|
|
}
|
|
.section-label {
|
|
margin: 0;
|
|
font-size: 0.9rem;
|
|
font-weight: 600;
|
|
}
|
|
.section-label .opt {
|
|
font-weight: 400;
|
|
font-size: 0.78rem;
|
|
opacity: 0.55;
|
|
}
|
|
.error {
|
|
margin: 0;
|
|
color: #c0392b;
|
|
font-size: 0.85rem;
|
|
}
|
|
.actions {
|
|
display: flex;
|
|
gap: 0.6rem;
|
|
}
|
|
.actions .primary-btn {
|
|
flex: 1;
|
|
}
|
|
.primary-btn {
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid hsla(160, 100%, 37%, 1);
|
|
border-radius: 8px;
|
|
background: hsla(160, 100%, 37%, 1);
|
|
color: #fff;
|
|
font-size: 0.95rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
}
|
|
.primary-btn:hover:not(:disabled) {
|
|
background: hsla(160, 100%, 32%, 1);
|
|
}
|
|
.primary-btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
.ghost-btn {
|
|
flex: 1;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 8px;
|
|
background: var(--color-background);
|
|
color: var(--color-text);
|
|
font-size: 0.95rem;
|
|
cursor: pointer;
|
|
}
|
|
.ghost-btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|