fix: login persistence, username login, realtime refresh, group name uniqueness
- Fix cookie path to '/' for auth persistence across page refreshes - Login field now accepts both username and email - Add 30s polling for group list and team session status refresh - Add group name uniqueness check before creation Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ pb.authStore.loadFromCookie(document.cookie)
|
|||||||
|
|
||||||
// 保存认证状态到 cookie
|
// 保存认证状态到 cookie
|
||||||
pb.authStore.onChange(() => {
|
pb.authStore.onChange(() => {
|
||||||
document.cookie = pb.authStore.exportToCookie({ httpOnly: false })
|
document.cookie = pb.authStore.exportToCookie({ httpOnly: false, path: '/' })
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取当前用户
|
// 获取当前用户
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useRouter } from 'vue-router'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { useGroupStore } from '@/stores/group'
|
import { useGroupStore } from '@/stores/group'
|
||||||
import { createGroup } from '@/api/groups'
|
import { createGroup } from '@/api/groups'
|
||||||
|
import pb from '@/api/pocketbase'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean
|
modelValue: boolean
|
||||||
@@ -33,7 +34,20 @@ async function handleSubmit() {
|
|||||||
ElMessage.warning('请输入群组名称')
|
ElMessage.warning('请输入群组名称')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查群组名是否重复
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const existing = await pb.collection('groups').getList(1, 1, {
|
||||||
|
filter: `name="${form.value.name.trim()}"`
|
||||||
|
})
|
||||||
|
if (existing.items.length > 0) {
|
||||||
|
ElMessage.warning('该群组名称已存在,请换一个')
|
||||||
|
loading.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const group = await createGroup({
|
const group = await createGroup({
|
||||||
name: form.value.name.trim(),
|
name: form.value.name.trim(),
|
||||||
|
|||||||
@@ -23,16 +23,28 @@ const showScheduleModal = ref(false)
|
|||||||
const showCreateGroup = ref(false)
|
const showCreateGroup = ref(false)
|
||||||
const showJoinGroup = ref(false)
|
const showJoinGroup = ref(false)
|
||||||
|
|
||||||
|
let refreshTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await userStore.initUser()
|
await userStore.initUser()
|
||||||
await groupStore.loadGroups()
|
await groupStore.loadGroups()
|
||||||
await teamStore.loadActiveSession()
|
await teamStore.loadActiveSession()
|
||||||
await notificationStore.loadPendingInvitations()
|
await notificationStore.loadPendingInvitations()
|
||||||
await notificationStore.startListening()
|
await notificationStore.startListening()
|
||||||
|
|
||||||
|
// 每30秒轮询刷新群组列表和临时小组状态
|
||||||
|
refreshTimer = setInterval(async () => {
|
||||||
|
await groupStore.loadGroups()
|
||||||
|
await teamStore.loadActiveSession()
|
||||||
|
}, 30000)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
notificationStore.stopListening()
|
notificationStore.stopListening()
|
||||||
|
if (refreshTimer) {
|
||||||
|
clearInterval(refreshTimer)
|
||||||
|
refreshTimer = null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ import PasswordInput from '@/components/common/PasswordInput.vue'
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const email = ref('')
|
const identity = ref('')
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
if (!email.value || !password.value) {
|
if (!identity.value || !password.value) {
|
||||||
ElMessage.warning('请输入邮箱和密码')
|
ElMessage.warning('请输入用户名/邮箱和密码')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
await userStore.login(email.value, password.value)
|
await userStore.login(identity.value, password.value)
|
||||||
|
|
||||||
const redirect = '/'
|
const redirect = '/'
|
||||||
router.push(redirect)
|
router.push(redirect)
|
||||||
@@ -45,12 +45,11 @@ async function handleLogin() {
|
|||||||
|
|
||||||
<form class="login-form" @submit.prevent="handleLogin">
|
<form class="login-form" @submit.prevent="handleLogin">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email">邮箱</label>
|
<label for="identity">用户名 / 邮箱</label>
|
||||||
<el-input
|
<el-input
|
||||||
id="email"
|
id="identity"
|
||||||
v-model="email"
|
v-model="identity"
|
||||||
type="email"
|
placeholder="请输入用户名或邮箱"
|
||||||
placeholder="请输入邮箱"
|
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user