pleroma-fe/src/stores/oauth_tokens.js

33 lines
784 B
JavaScript
Raw Normal View History

import { defineStore } from 'pinia'
2026-06-16 17:32:26 +03:00
import { useOAuthStore } from 'src/stores/oauth.js'
2026-06-15 20:02:22 +03:00
2026-06-17 14:36:45 +03:00
import { fetchOAuthTokens, revokeOAuthToken } from 'src/api/user.js'
2026-06-15 20:02:22 +03:00
export const useOAuthTokensStore = defineStore('oauthTokens', {
state: () => ({
2026-01-06 16:22:52 +02:00
tokens: [],
}),
actions: {
2026-01-06 16:22:52 +02:00
fetchTokens() {
2026-06-15 20:02:22 +03:00
fetchOAuthTokens({
2026-06-16 17:32:26 +03:00
credentials: useOAuthStore().token,
2026-06-22 16:13:30 +03:00
}).then(({ data: tokens }) => {
2026-06-15 20:02:22 +03:00
this.swapTokens(tokens)
})
},
2026-01-06 16:22:52 +02:00
revokeToken(id) {
2026-06-15 20:02:22 +03:00
revokeOAuthToken({
id,
2026-06-16 17:32:26 +03:00
credentials: useOAuthStore().token,
2026-06-22 19:44:44 +03:00
}).then(({ status }) => {
if (status === 201) {
2026-06-15 20:02:22 +03:00
this.swapTokens(this.tokens.filter((token) => token.id !== id))
}
})
},
2026-01-06 16:22:52 +02:00
swapTokens(tokens) {
this.tokens = tokens
2026-01-06 16:22:52 +02:00
},
},
})