Skip to content

Commit 9315469

Browse files
committed
PWA: keep the login status in the store.
1 parent c0126bf commit 9315469

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

pwa/src/components/buttons/SyncButton.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const isModalOpen = ref(false);
1111
const isSubmitting = ref(false);
1212
const password = ref("");
1313
const errorMessage = ref("");
14-
const isLoggedIn = ref(false);
1514
1615
function openModal() {
1716
isModalOpen.value = true;
@@ -28,11 +27,11 @@ function checkLoginStatus() {
2827
for (const cookie of cookies) {
2928
if (cookie.startsWith("flowey_session_key_present")) {
3029
password.value = "";
31-
isLoggedIn.value = true;
30+
state.isLoggedIn.value = true;
3231
return;
3332
}
3433
}
35-
isLoggedIn.value = false;
34+
state.isLoggedIn.value = false;
3635
}
3736
3837
async function handleSubmit() {
@@ -59,7 +58,7 @@ async function handleSubmit() {
5958
6059
if (response.ok) {
6160
checkLoginStatus();
62-
if (!isLoggedIn.value) {
61+
if (!state.isLoggedIn.value) {
6362
errorMessage.value = "Login failed: no session key received.";
6463
}
6564
} else {
@@ -103,7 +102,7 @@ async function handleLogout() {
103102
104103
if (response.ok) {
105104
checkLoginStatus();
106-
if (isLoggedIn.value) {
105+
if (state.isLoggedIn.value) {
107106
errorMessage.value = "Logout failed: session key is not invalidated.";
108107
}
109108
} else {
@@ -133,7 +132,10 @@ onMounted(() => {
133132
</script>
134133

135134
<template>
136-
<Button @click="openModal">
135+
<Button
136+
:class="!state.isLoggedIn.value && 'suggested'"
137+
@click="openModal"
138+
>
137139
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
138140
<path class="background" d="M 22.153846,1.8461538 H 1.8461538 V 22.153846 H 22.153846 Z" fill="none" />
139141
<!-- eslint-disable-next-line max-len -->
@@ -151,7 +153,7 @@ onMounted(() => {
151153
<h2>Sync</h2>
152154
<CancelButton @click="closeModal" />
153155
</div>
154-
<template v-if="!isLoggedIn">
156+
<template v-if="!state.isLoggedIn.value">
155157
<form @submit.prevent="handleSubmit">
156158
<div class="form-group">
157159
<label for="endpoint">Endpoint:</label>

pwa/src/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export class State {
4040
isReverseOn = ref(false);
4141
maxTime = new MaxTime();
4242
targetDate = ref(Date.now());
43+
4344
endpoint = ref("");
4445
username = ref("");
46+
isLoggedIn = ref(false);
4547

4648
* [Symbol.iterator]() {
4749
for (const property in this) {

0 commit comments

Comments
 (0)