Skip to content

Commit

Permalink
fix: reauthenticate app-user in case of existing session
Browse files Browse the repository at this point in the history
  • Loading branch information
ohrstrom committed Jun 26, 2023
1 parent 390b919 commit 81846a8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/app-bridge/appBridge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useIntervalFn } from "@vueuse/core";
import log from "loglevel";

import { useAccount } from "@/composables/account";
import { useDevice } from "@/composables/device";
import { usePlayerStore } from "@/stores/player";
import { useQueueStore } from "@/stores/queue";
Expand Down Expand Up @@ -64,12 +65,14 @@ type receiveChannel =
| "player:update"
// schedule
| "schedule:update"
// settings
| "settings:update"
// ui
| "ui:update"
// rating
| "rating:update"
// settings
| "settings:update"
// settings
| "account:update"
// sign-in
| "googleSignin:completed";

Expand Down Expand Up @@ -152,16 +155,22 @@ class AppBridge {
heartbeatDelay: HEARTBEAT_HEARTBEAT_DELAY,
};
await this.send("heartbeat:setDelays", delays);

// send accessToken in case of existing user session
const { user } = useAccount();
if (user.value?.accessToken) {
await this.send("account:setAccessToken", {accessToken: user.value?.accessToken})
}
}
async heartbeat(): Promise<void> {
// log.debug("AppBridge - heartbeat");
await this.send("heartbeat");
}
// web > native - SEND payload TO swift-app channel
async send(channel: sendChannel, data?: object) {
// if (channel !== "heartbeat") {
// log.debug("AppBridge - send", channel, data);
// }
if (channel !== "heartbeat") {
log.debug("AppBridge - send", channel, data);
}
const message: SendMessage = {
c: channel,
};
Expand Down Expand Up @@ -219,6 +228,9 @@ class AppBridge {
await setSchedule(data.schedule);
break;
}
case "account:update": {
break;
}
case "googleSignin:completed": {
await this.loginByIdToken(data);
break;
Expand Down

0 comments on commit 81846a8

Please sign in to comment.