Fix an error when logging out was causing state issues

This commit is contained in:
Jonathan Bourdon
2024-08-05 13:17:22 -04:00
parent 9cbf63339a
commit 3a98b38a71
5 changed files with 12 additions and 11 deletions

View File

@@ -9,8 +9,10 @@ export const useAuthStore = defineStore(
() => { () => {
const clientApi = useClient() const clientApi = useClient()
const router = useRouter() const router = useRouter()
const accessToken = useSessionStorage('auth-accessToken', undefined) const accessToken = useSessionStorage('auth-accessToken', undefined)
const refreshToken = useSessionStorage('auth-refreshToken', undefined) const refreshToken = useSessionStorage('auth-refreshToken', undefined)
const isAuthenticated = computed(() => !!accessToken.value) const isAuthenticated = computed(() => !!accessToken.value)
function updateTokens(data) { function updateTokens(data) {
@@ -25,9 +27,9 @@ export const useAuthStore = defineStore(
}) })
} }
function logout() { async function logout() {
cleanTokens() cleanTokens()
router.push('/') await router.push('/')
} }
async function login(email, password) { async function login(email, password) {

View File

@@ -10,7 +10,7 @@ export const useUserStore = defineStore(
const authStore = useAuthStore() const authStore = useAuthStore()
const authWatcher = watch( const authWatcher = watch(
() => authStore.isAuthenticated, () => authStore.isAuthenticated,
async (newValue, oldValue) => { async (newValue) => {
if (newValue) { if (newValue) {
await fetchCurrentUserProfile() await fetchCurrentUserProfile()
} else { } else {

View File

@@ -45,16 +45,15 @@ const creatorIdWatcher = watch(
(newCreatorId) => { (newCreatorId) => {
if (newCreatorId) { if (newCreatorId) {
// Reset contents and last_id when the creatorId changes // Reset contents and last_id when the creatorId changes
contents.value = []; contents.value = []
last_id = null; last_id = null
// Fetch contents for the new creator // Fetch contents for the new creator
fetchContents({ fetchContents({
done: () => { done: () => {
} }
}); });
} }
}, })
{immediate: true})
async function fetchContents({done}) { async function fetchContents({done}) {
try { try {

View File

@@ -61,7 +61,7 @@ const closeDialog = () => {
<template> <template>
<button <button
v-if="creator.id === userStore.user.id" v-if="creator && userStore.user && creator.id === userStore.user.id"
class="flex items-center text-white transform transition-transform duration-200 hover:text-gray-300 hover:scale-125 px-4" class="flex items-center text-white transform transition-transform duration-200 hover:text-gray-300 hover:scale-125 px-4"
@click="isDialogActive = true"> @click="isDialogActive = true">
<v-icon style="font-size: 35px; height: 35px; width: 55px;">mdi-text-box-plus-outline</v-icon> <v-icon style="font-size: 35px; height: 35px; width: 55px;">mdi-text-box-plus-outline</v-icon>

View File

@@ -59,7 +59,7 @@
<div class="text-2xl text-center lg:text-left"> <div class="text-2xl text-center lg:text-left">
<p :style="{ color: creator.profileColors.accent }">{{ creator.occupation }}</p> <p :style="{ color: creator.profileColors.accent }">{{ creator.occupation }}</p>
</div> </div>
<div class="text-lg text-white" >{{creator.subscriberCount}} Abonnés</div> <div class="text-lg text-white">{{ creator.subscriberCount }} Abonnés</div>
</div> </div>
<!-- Buttons --> <!-- Buttons -->
@@ -69,7 +69,7 @@
<subscribe-button :creator="creator"></subscribe-button> <subscribe-button :creator="creator"></subscribe-button>
<CreatePostButton :creator="creator"/> <publish-content-button :creator="creator"/>
</div> </div>
@@ -79,10 +79,10 @@
</template> </template>
<script setup> <script setup>
import CreatePostButton from "@/views/contents/CreatePostButton.vue";
import SizeIndicator from "@/views/tools/SizeIndicator.vue"; import SizeIndicator from "@/views/tools/SizeIndicator.vue";
import AboutYou from "@/views/creators/CreatorDescriptionBtn.vue"; import AboutYou from "@/views/creators/CreatorDescriptionBtn.vue";
import SubscribeButton from "@/views/creators/SubscribeButton.vue"; import SubscribeButton from "@/views/creators/SubscribeButton.vue";
import PublishContentButton from "@/views/contents/PublishContentButton.vue";
const props = defineProps({ const props = defineProps({
creator: {type: Object, required: true}, creator: {type: Object, required: true},