angular - Angular Laravel Pusher 419 unknown status when trying to auth user
问题描述
I'm trying to implement chat using Angular, Laravel and Pusher. The chat is working but now i want to auth the user in order to have indication if the user is online or not. I understood that in order to do this i need to make private rooms instead of public rooms, When i'm trying to make auth for the users i'm getting 419 unknown status.
Angular Code:
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { UserSessionService } from 'app/shared/_services/user-session.service';
import { ChatMessage } from 'app/shared/_models/chat-message.model';
import { environment } from 'environments/environment';
declare const Pusher: any;
@Injectable()
export class BroadcastService {
readonly pusherKey = environment.pusherKey;
private channels = {};
newChatMessage = new Subject<ChatMessage>();
activeChanel = new Subject<any>();
constructor(private userSession: UserSessionService) {}
openChatSocket(chatId: number): void {
if (this.channels[chatId]) {
return;
}
const pusher = new Pusher(this.pusherKey, {
cluster: 'eu',
encrypted: true,
authEndpoint: environment.apiUrl + '/broadcasting/auth',
auth: {
headers: {
'Authorization': this.userSession.getToken()
}
}
});
this.channels[chatId] = pusher.subscribe('private-chat-' + chatId);
this.activeChanel.next(this.channels[chatId])
this.channels[chatId].bind('new-message', fullMessageInfo => {
this.newChatMessage.next(fullMessageInfo.message);
});
}
closeChatSockets(): void {
Object.keys(this.channels).forEach(channel => {
this.channels[channel].unsubscribe();
});
this.channels = {};
}
}
I already tried to exclude http://localhost:4200 in VerifyCsrfToken.php and it didn't work.
解决方案
推荐阅读
- r - 基于R中的用户输入创建数据框的函数
- python - 当将两个几乎相同的元组添加到一个集合时,使它们被认为是相同的
- c# - Azure Service Fabric 中节点之间的广播消息
- javascript - 您可以使用变量进行变量调用吗?Javascript
- flutter - 如何在颤动中将图像从路径转换为Base64?
- shell - 如何将带有特殊字符和空格的参数传递给 C-Shell 脚本
- excel - 每次另一个单元格非零时,计数器加 1
- python - 使用带有python的日期的MySQL查询总是返回相同的ID
- node.js - Node.js:同步子进程生成
- postgresql - 如何在golang中使用可变参数更新postgres JSONB?