0bce40a5bf
後端 - 新增 6 個 Notification class(預約建立/確認/拒絕/取消/完成、收到評價),database + mail 雙 channel - 新增 NotificationController(list / unread-count / markRead / markAllRead / destroy) - 整合通知觸發至 MemberBookingController、ProviderBookingController、CompleteFinishedBookings、ReviewController - 新增 notifications / jobs / failed_jobs migration - Docker Compose 加入 queue-worker、mailpit service - DivingOffer 補上 provider() 關聯 前端 - 新增 notificationStore(Polling 30s/60s 自適應 + Page Visibility API) - 新增 NotificationBell(未讀 Badge)、NotificationDrawer(側邊通知中心) - main.js:auth store init 前置於 router.use(),修正 beforeEach guard 時序問題 - notificationAxios:依路徑動態選擇 member/coach token - NotificationDrawer:改用 new URL().pathname 提取 action_url 路徑 OpenSpec - 歸檔 notification-system change - 同步 notification-core / notification-email / notification-triggers specs 至主規格 - 更新 booking-lifecycle / review-lifecycle spec(補充通知觸發 requirement) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import api from '../api/axios'
|
|
import { useNotificationStore } from './notifications'
|
|
|
|
export const useAuthStore = defineStore('auth', () => {
|
|
const user = ref(null)
|
|
const token = ref(null)
|
|
|
|
const isLoggedIn = computed(() => !!token.value)
|
|
|
|
function init() {
|
|
const saved = localStorage.getItem('token')
|
|
const savedUser = localStorage.getItem('user')
|
|
if (saved) {
|
|
token.value = saved
|
|
user.value = savedUser ? JSON.parse(savedUser) : null
|
|
useNotificationStore().startPolling()
|
|
}
|
|
}
|
|
|
|
function setAuth(userData, tokenValue) {
|
|
user.value = userData
|
|
token.value = tokenValue
|
|
localStorage.setItem('token', tokenValue)
|
|
localStorage.setItem('user', JSON.stringify(userData))
|
|
useNotificationStore().startPolling()
|
|
}
|
|
|
|
async function logout() {
|
|
try {
|
|
await api.post('/member/logout')
|
|
} catch {}
|
|
useNotificationStore().stopPolling()
|
|
user.value = null
|
|
token.value = null
|
|
localStorage.removeItem('token')
|
|
localStorage.removeItem('user')
|
|
}
|
|
|
|
return { user, token, isLoggedIn, init, setAuth, logout }
|
|
})
|