Skip to content

Commit 48987a0

Browse files
authored
fix: check if auth token is valid (#230)
1 parent 6e9767c commit 48987a0

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

app/src/core/game.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { go } from '@/router';
55
import * as commands from '@/commands';
66
import { handleError } from '@/lib/error';
7+
import { useUserStore } from '@/stores/user';
78
import { Entity } from '@/core/entity/abstract';
89
import { exit } from '@tauri-apps/plugin-process';
910

@@ -114,11 +115,12 @@ export async function leaveGame() {
114115
handleError(err);
115116
}
116117
finally {
117-
if (await commands.isLocal()) {
118-
await go('home');
118+
const { isAuthorizationTokenValid } = useUserStore();
119+
if (await commands.isRemote() && await isAuthorizationTokenValid()) {
120+
await go('lobby');
119121
}
120122
else {
121-
await go('lobby');
123+
await go('home');
122124
}
123125
}
124126
}

app/src/stores/user.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import * as commands from '@/commands';
88
export const useUserStore = defineStore('user', () => {
99
const authorizationToken = ref<Option<string>>(null);
1010

11+
async function isAuthorizationTokenValid() {
12+
if (authorizationToken.value) {
13+
return Boolean(await commands.validateToken(authorizationToken.value));
14+
}
15+
else {
16+
return false;
17+
}
18+
}
19+
1120
async function updateClient(options: Partial<ClientOptions> = {}) {
1221
await commands.updateClient({
1322
...options,
@@ -18,6 +27,7 @@ export const useUserStore = defineStore('user', () => {
1827

1928
return {
2029
authorizationToken,
30+
isAuthorizationTokenValid,
2131
updateClient,
2232
};
2333
});

0 commit comments

Comments
 (0)