Init
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {useApi} from "@/composables/useApi";
|
||||
import {useGatewayStore} from "@/stores/gateway.ts";
|
||||
|
||||
export interface User {
|
||||
id: string
|
||||
@@ -36,6 +37,10 @@ export const useAuthStore = defineStore('auth', {
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
this.user = data.user
|
||||
|
||||
// Initialisation du gateway
|
||||
const gatewayStore = useGatewayStore()
|
||||
await gatewayStore.connect()
|
||||
} else {
|
||||
this.logout()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import {defineStore} from 'pinia';
|
||||
import {useAppStore} from "@/stores/app.ts";
|
||||
import {useAuthStore} from "@/stores/auth.ts";
|
||||
|
||||
type GatewayStatus = 'disconnected' | 'connecting' | 'connected' | 'error'
|
||||
|
||||
@@ -15,9 +17,21 @@ export const useGatewayStore = defineStore('gateway', {
|
||||
return
|
||||
}
|
||||
|
||||
this.status = 'connecting'
|
||||
const appStore = useAppStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const wsUrl = `ws://localhost:3000/ws`
|
||||
|
||||
this.status = 'connecting'
|
||||
const token = authStore.token
|
||||
if (!token) {
|
||||
this.status = 'error'
|
||||
return
|
||||
}
|
||||
|
||||
const apiUri = appStore.baseurl ? new URL(appStore.baseurl) : new URL(window.location.href)
|
||||
const wsProtocol = apiUri.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
|
||||
const wsUrl = `${wsProtocol}//${apiUri.host}/ws/gateway?token=${encodeURIComponent(token)}`
|
||||
const socket = new WebSocket(wsUrl)
|
||||
|
||||
socket.onopen = () => {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import {defineStore} from "pinia";
|
||||
|
||||
export const useServerStore = defineStore("server", {
|
||||
state: () => ({}),
|
||||
state: () => ({
|
||||
servers: []
|
||||
}),
|
||||
actions: {}
|
||||
});
|
||||
Reference in New Issue
Block a user