Skip to content

Commit

Permalink
clear codes
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Feb 10, 2025
1 parent 21d8631 commit 651ea47
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions app/javascripts/stimulus_channels/session_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ import BaseCable from './base_cable'
export default class extends BaseCable {

connect() {
this.subscription = BaseCable.consumer.subscriptions.create({channel: 'Com::SessionChannel', room: 'room'}, {
received(data) {
const url = data.url || '/'
if (data.auth_token) {
document.addEventListener('turbo:before-fetch-request', event => {
const xhr = event.detail.fetchOptions
xhr.headers['Authorization'] = data.auth_token
})
}
Turbo.visit(url)
},
this.subscription = BaseCable.consumer.subscriptions.create(
{
channel: 'Com::SessionChannel',
room: 'room'
},
{
received(data) {
const url = data.url || '/'
if (data.auth_token) {
document.addEventListener('turbo:before-fetch-request', event => {
const xhr = event.detail.fetchOptions
xhr.headers['Authorization'] = data.auth_token
})
}
Turbo.visit(url)
},

connected() {
console.debug('connected:', this.identifier)
},
connected() {
console.debug('connected:', this.identifier)
},

disconnected() {
console.debug('disconnected:', this.identifier)
}
})
disconnected() {
console.debug('disconnected:', this.identifier)
}
}
)
}

disconnect() {
Expand Down

0 comments on commit 651ea47

Please sign in to comment.