Skip to content

Commit

Permalink
🚧 how do we duplicate this invalidate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Oct 8, 2023
1 parent c7034e1 commit b10f715
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions client/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ export default class Api {
constructor(config: AuthConfig) {
this.config = { ...authConfigDefaults, ...config }
}

public async invalidate(): Promise<void> {
this.token.value = undefined
this.loggedIn.value = false
Object.assign(this.$user, {})
navigateTo(this.config.redirect.logout)
}

setNuxtApp(nuxtApp:NuxtApp) {
this.nuxtApp = nuxtApp
}
Expand Down Expand Up @@ -188,8 +180,8 @@ export default class Api {
}

public async toastError(error: any): Promise<any> {
if (error.response?.status === 401)
return await this.invalidate()
if (error.response?.status === 401) {
}

if (error.response?.status === 402 && this.config.paymentToast)
return useToast().add(this.config.paymentToast)
Expand Down Expand Up @@ -224,11 +216,19 @@ export default class Api {
}
}

public async invalidate(): Promise<void> {
this.token.value = undefined
this.loggedIn.value = false
Object.assign(this.$user, {})
navigateTo(this.config.redirect.logout)
}

public async logout(): Promise<void> {
if (this.$echo)
this.$echo.disconnect()
const response = (await $fetch<api.MetApiResponse>('/logout', this.fetchOptions()))
useToast().add({ icon: 'i-mdi-check-bold', color: 'green', title: response.data.message, timeout: 1 })
await this.invalidate()
}

}

0 comments on commit b10f715

Please sign in to comment.