fix: 避免 entrypoint 覆寫 .env 的 DB 憑證 #11
@@ -16,7 +16,9 @@ class BookingPresenceChannel
|
|||||||
$booking->loadMissing('schedule');
|
$booking->loadMissing('schedule');
|
||||||
|
|
||||||
$isMember = $user->role === 'member' && $booking->member_id === $user->id;
|
$isMember = $user->role === 'member' && $booking->member_id === $user->id;
|
||||||
$isProvider = $user->role === 'provider' && $booking->schedule->provider_id === $user->id;
|
$isProvider = $user->role === 'provider'
|
||||||
|
&& $booking->schedule !== null
|
||||||
|
&& $booking->schedule->provider_id === $user->id;
|
||||||
|
|
||||||
if (!$isMember && !$isProvider) {
|
if (!$isMember && !$isProvider) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -170,15 +170,24 @@ function subscribeChannel() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleReconnected() {
|
||||||
|
if (!isConfirmed.value) return
|
||||||
|
echo.leave(`booking.${props.bookingId}`)
|
||||||
|
channel.value = null
|
||||||
|
subscribeChannel()
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await requestBrowserNotificationPermission()
|
await requestBrowserNotificationPermission()
|
||||||
await loadHistory()
|
await loadHistory()
|
||||||
if (isConfirmed.value) {
|
if (isConfirmed.value) {
|
||||||
subscribeChannel()
|
subscribeChannel()
|
||||||
|
echo.connector.pusher.connection.bind('reconnected', handleReconnected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
echo.connector.pusher.connection.unbind('reconnected', handleReconnected)
|
||||||
if (channel.value) {
|
if (channel.value) {
|
||||||
channel.value.whisper('presence', { user_type: props.currentUserType, online: false })
|
channel.value.whisper('presence', { user_type: props.currentUserType, online: false })
|
||||||
echo.leave(`booking.${props.bookingId}`)
|
echo.leave(`booking.${props.bookingId}`)
|
||||||
|
|||||||
@@ -27,10 +27,13 @@ const echo = new Echo({
|
|||||||
// 登入後更新 auth header,讓 presence channel 授權帶正確 token
|
// 登入後更新 auth header,讓 presence channel 授權帶正確 token
|
||||||
export function updateEchoToken() {
|
export function updateEchoToken() {
|
||||||
const token = getAuthToken()
|
const token = getAuthToken()
|
||||||
echo.options.auth.headers.Authorization = `Bearer ${token}`
|
const bearer = `Bearer ${token}`
|
||||||
// 重新連線讓新 token 生效
|
echo.options.auth.headers.Authorization = bearer
|
||||||
echo.disconnect()
|
// 同步更新 Pusher 內部 config(避免 Pusher.js 持有舊的 header copy)
|
||||||
echo.connect()
|
if (echo.connector?.pusher?.config?.auth?.headers) {
|
||||||
|
echo.connector.pusher.config.auth.headers.Authorization = bearer
|
||||||
|
}
|
||||||
|
// 不 disconnect/connect:避免中斷 BookingChat 已訂閱的 presence channel
|
||||||
}
|
}
|
||||||
|
|
||||||
export default echo
|
export default echo
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
localStorage.setItem('user', JSON.stringify(userData))
|
localStorage.setItem('user', JSON.stringify(userData))
|
||||||
const ns = useNotificationStore()
|
const ns = useNotificationStore()
|
||||||
ns.startPolling()
|
ns.startPolling()
|
||||||
ns.startRealtime(userData.id)
|
|
||||||
updateEchoToken()
|
updateEchoToken()
|
||||||
|
ns.startRealtime(userData.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ export const useCoachAuthStore = defineStore('coachAuth', () => {
|
|||||||
localStorage.setItem('coach_user', JSON.stringify(userData))
|
localStorage.setItem('coach_user', JSON.stringify(userData))
|
||||||
const ns = useNotificationStore()
|
const ns = useNotificationStore()
|
||||||
ns.startPolling()
|
ns.startPolling()
|
||||||
ns.startRealtime(userData.id)
|
|
||||||
updateEchoToken()
|
updateEchoToken()
|
||||||
|
ns.startRealtime(userData.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
|
|||||||
Reference in New Issue
Block a user