User rename fixes.

This commit is contained in:
Leo Vasanko 2025-09-01 18:20:32 -06:00
parent 37eaffff3f
commit 6d6c4ee35d
3 changed files with 13 additions and 24 deletions

View File

@ -367,17 +367,17 @@ function closeDialog() { dialog.value = { type: null, data: null, busy: false, e
// Admin user rename
const editingUserName = ref(false)
const editUserNameValue = ref('')
const editUserNameValid = computed(()=> editUserNameValue.value.trim().length > 0 && editUserNameValue.value.trim().length <= 64)
const editUserNameValid = computed(()=> true) // backend validates
function beginEditUserName() {
if (!selectedUser.value) return
editingUserName.value = true
editUserNameValue.value = userDetail.value?.display_name || selectedUser.value.display_name || ''
editUserNameValue.value = ''
}
function cancelEditUserName() { editingUserName.value = false }
async function submitEditUserName() {
if (!editingUserName.value || !editUserNameValid.value) return
if (!editingUserName.value) return
try {
const res = await fetch(`/auth/admin/users/${selectedUser.value.uuid}/display-name`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: editUserNameValue.value.trim() }) })
const res = await fetch(`/auth/admin/users/${selectedUser.value.uuid}/display-name`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: editUserNameValue.value }) })
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Rename failed')
editingUserName.value = false
await loadOrgs()
@ -487,8 +487,8 @@ async function submitDialog() {
<h2 class="user-title">
<span v-if="!editingUserName">{{ userDetail?.display_name || selectedUser.display_name }} <button class="icon-btn" @click="beginEditUserName" title="Rename user"></button></span>
<span v-else>
<input v-model="editUserNameValue" maxlength="64" @keyup.enter="submitEditUserName" />
<button class="icon-btn" @click="submitEditUserName" :disabled="!editUserNameValid">💾</button>
<input v-model="editUserNameValue" :placeholder="userDetail?.display_name || selectedUser.display_name" maxlength="64" @keyup.enter="submitEditUserName" />
<button class="icon-btn" @click="submitEditUserName">💾</button>
<button class="icon-btn" @click="cancelEditUserName"></button>
</span>
</h2>

View File

@ -7,8 +7,8 @@
👤
<template v-if="!editingName">{{ authStore.userInfo.user.user_name }} <button class="mini-btn" @click="startEdit" title="Edit name"></button></template>
<template v-else>
<input v-model="newName" :disabled="authStore.isLoading" maxlength="64" @keyup.enter="saveName" />
<button class="mini-btn" @click="saveName" :disabled="!validName || authStore.isLoading">💾</button>
<input v-model="newName" :placeholder="authStore.userInfo.user.user_name" :disabled="authStore.isLoading" maxlength="64" @keyup.enter="saveName" />
<button class="mini-btn" @click="saveName" :disabled="authStore.isLoading">💾</button>
<button class="mini-btn" @click="cancelEdit" :disabled="authStore.isLoading"></button>
</template>
</h3>
@ -159,14 +159,12 @@ const isAdmin = computed(() => !!(authStore.userInfo?.is_global_admin || authSto
// Name editing state & actions
const editingName = ref(false)
const newName = ref('')
const validName = computed(() => newName.value.trim().length > 0 && newName.value.trim().length <= 64)
function startEdit() { editingName.value = true; newName.value = authStore.userInfo?.user?.user_name || '' }
function startEdit() { editingName.value = true; newName.value = '' }
function cancelEdit() { editingName.value = false }
async function saveName() {
if (!validName.value) return
try {
authStore.isLoading = true
const res = await fetch('/auth/user/display-name', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: newName.value.trim() }) })
const res = await fetch('/auth/user/display-name', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: newName.value }) })
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Update failed')
await authStore.loadUserInfo()
editingName.value = false

View File

@ -28,26 +28,17 @@
<script setup>
import { useAuthStore } from '@/stores/auth'
import passkey from '@/utils/passkey'
import { ref, watchEffect } from 'vue'
import { ref } from 'vue'
const authStore = useAuthStore()
const user_name = ref('')
// Initialize local name from store (once loaded)
watchEffect(() => {
if (!user_name.value && authStore.userInfo?.user?.user_name) {
user_name.value = authStore.userInfo.user.user_name
}
})
const user_name = ref('') // intentionally blank; original shown via placeholder
async function register() {
authStore.isLoading = true
authStore.showMessage('Starting registration...', 'info')
try {
const trimmed = (user_name.value || '').trim()
const nameToSend = trimmed.length ? trimmed : null
const result = await passkey.register(authStore.resetToken, nameToSend)
const result = await passkey.register(authStore.resetToken, user_name.value)
console.log("Result", result)
await authStore.setSessionCookie(result.session_token)
// resetToken cleared by setSessionCookie; ensure again