feat: auth ws
- add auth message on connect Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
30f8ab773f
commit
dc327e7779
2 changed files with 22 additions and 0 deletions
|
|
@ -4,7 +4,9 @@ import { get, writable } from 'svelte/store';
|
||||||
import { handleIncomingMessages } from '../handlers/messageHandler';
|
import { handleIncomingMessages } from '../handlers/messageHandler';
|
||||||
import { queue as msgQueue, sendMessage } from '../handlers/ws_messageSender';
|
import { queue as msgQueue, sendMessage } from '../handlers/ws_messageSender';
|
||||||
import { auth } from '../client/firebase';
|
import { auth } from '../client/firebase';
|
||||||
|
import { auth as authStore } from '$lib/core/stores/auth';
|
||||||
import { addNotification } from './noti';
|
import { addNotification } from './noti';
|
||||||
|
import { permission } from './permissions';
|
||||||
|
|
||||||
let socket: WebSocket | null = null;
|
let socket: WebSocket | null = null;
|
||||||
const ENABLE_WS_DEBUG: boolean = false;
|
const ENABLE_WS_DEBUG: boolean = false;
|
||||||
|
|
@ -21,6 +23,25 @@ export function connectToWebsocket() {
|
||||||
socketStore.set(socket);
|
socketStore.set(socket);
|
||||||
addNotification('INFO:Connected!');
|
addNotification('INFO:Connected!');
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
// send auth message
|
||||||
|
|
||||||
|
let auth_data = get(authStore);
|
||||||
|
let perms = get(permission);
|
||||||
|
|
||||||
|
sendMessage({
|
||||||
|
type: 'auth',
|
||||||
|
payload: {
|
||||||
|
user: {
|
||||||
|
uid: auth_data?.uid ?? '',
|
||||||
|
name: auth_data?.displayName ?? '',
|
||||||
|
email: auth_data?.email ?? '',
|
||||||
|
permissions: perms.join(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// recover messages on connect, flushing
|
// recover messages on connect, flushing
|
||||||
while (get(msgQueue).length) {
|
while (get(msgQueue).length) {
|
||||||
let queue = get(msgQueue);
|
let queue = get(msgQueue);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ export type OutMessage =
|
||||||
type: 'auth';
|
type: 'auth';
|
||||||
payload: {
|
payload: {
|
||||||
user: {
|
user: {
|
||||||
|
uid: string;
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
permissions: string;
|
permissions: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue