making login work for prod

This commit is contained in:
metacryst
2026-03-16 07:56:40 -05:00
parent a626abe1c3
commit 69b359d9a1
9 changed files with 81 additions and 23 deletions

View File

@@ -1,3 +1,6 @@
import { Preferences } from '@capacitor/preferences';
const env = import.meta.env
class Connection {
connectionTries = 0;
ws;
@@ -8,10 +11,14 @@ class Connection {
}
init = async () => {
const { value: token } = await Preferences.get({ key: 'auth_token' });
return new Promise((resolve, reject) => {
const url = window.location.hostname.includes("local")
? "ws://" + window.location.host + "/ws"
: "wss://" + window.location.hostname + window.location.pathname + "/ws";
let url = ""
if(env.VITE_API_URL) {
url = "wss://" + env.VITE_API_URL.replace(/^https?:\/\//, '') + "/ws" + `?token=${token}`;
} else {
url = "ws://" + window.location.host + "/ws"
}
this.ws = new WebSocket(url);