Revoke access token when logging out

This commit is contained in:
silverpill 2022-11-15 17:54:43 +00:00
parent dcbbebd78f
commit e60032a405
2 changed files with 18 additions and 1 deletions

View file

@ -158,6 +158,21 @@ export async function getAccessToken(
}
}
export async function revokeAccessToken(
authToken: string,
): Promise<void> {
const url = `${BACKEND_URL}/oauth/revoke`
const response = await http(url, {
method: "POST",
authToken,
json: { token: authToken },
})
if (response.status !== 200) {
const data = await response.json()
throw new Error(data.message)
}
}
export async function getCurrentUser(authToken: string): Promise<User | null> {
const url = `${BACKEND_URL}/api/v1/accounts/verify_credentials`
const response = await http(url, { authToken })

View file

@ -39,6 +39,7 @@ import { onMounted } from "vue"
import { $, $computed } from "vue/macros"
import { useRouter } from "vue-router"
import { revokeAccessToken } from "@/api/users"
import { useNotifications } from "@/store/notifications"
import { useCurrentUser } from "@/store/user"
import { useInstanceInfo } from "@/store/instance"
@ -68,7 +69,8 @@ function isSubscriptionsFeatureEnabled(): boolean {
return Boolean(blockchain?.features.subscriptions)
}
function logout() {
async function logout() {
await revokeAccessToken(ensureAuthToken())
setCurrentUser(null)
setAuthToken(null)
router.push({ name: "landing-page" })