feat: auth ws

- add auth message on connect

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-04-28 17:20:32 +07:00
parent 30f8ab773f
commit dc327e7779
2 changed files with 22 additions and 0 deletions

View file

@ -4,7 +4,9 @@ import { get, writable } from 'svelte/store';
import { handleIncomingMessages } from '../handlers/messageHandler';
import { queue as msgQueue, sendMessage } from '../handlers/ws_messageSender';
import { auth } from '../client/firebase';
import { auth as authStore } from '$lib/core/stores/auth';
import { addNotification } from './noti';
import { permission } from './permissions';
let socket: WebSocket | null = null;
const ENABLE_WS_DEBUG: boolean = false;
@ -21,6 +23,25 @@ export function connectToWebsocket() {
socketStore.set(socket);
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
while (get(msgQueue).length) {
let queue = get(msgQueue);

View file

@ -17,6 +17,7 @@ export type OutMessage =
type: 'auth';
payload: {
user: {
uid: string;
name: string;
email: string;
permissions: string;