fix: token not refresh

- force refresh token if connect ws fail

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-06-17 16:43:26 +07:00
parent a95e7bbb13
commit ea7ec00b4b
2 changed files with 7 additions and 2 deletions

View file

@ -74,7 +74,7 @@ export async function sendMessage(
// console.log('send v2', APP_VERSION, semver.satisfies(APP_VERSION, '^0.0.2'));
if (semver.satisfies(APP_VERSION, '^0.0.2')) {
console.log('sending secured');
// console.log('sending secured');
let sharedKeyRes = get(sharedKey);
// do encrypt

View file

@ -123,6 +123,7 @@ export async function connectToWebsocket(id_token?: string) {
socketConnectionOfflineCount.set(0);
socketAlreadySendHeartbeat.set(0);
id_token = await auth.currentUser?.getIdToken(true);
await connectToWebsocket(id_token);
return;
@ -146,6 +147,7 @@ export async function connectToWebsocket(id_token?: string) {
console.log('try reconnect websocket ...');
// retry again
reconnectTimeout = setTimeout(async () => {
id_token = await auth.currentUser?.getIdToken(true);
await connectToWebsocket(id_token);
}, 5000);
}
@ -165,7 +167,10 @@ export async function connectToWebsocket(id_token?: string) {
if (auth.currentUser && !socket) {
console.log('try reconnect websocket ...');
// retry again
reconnectTimeout = setTimeout(async () => await connectToWebsocket(id_token), 5000);
reconnectTimeout = setTimeout(async () => {
id_token = await auth.currentUser?.getIdToken(true);
await connectToWebsocket(id_token);
}, 5000);
}
});