Skip to content

Commit

Permalink
enhance: プラグイン削除時にアクセストークンも削除する (misskey-dev#12167)
Browse files Browse the repository at this point in the history
* (enhance) プラグイン削除時にトークンも削除

* update changelog
  • Loading branch information
kakkokari-gtyih authored and kanarikanaru committed Nov 2, 2023
1 parent 7139c20 commit d061c97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
29 changes: 22 additions & 7 deletions packages/backend/src/server/api/endpoints/i/revoke-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export const paramDef = {
type: 'object',
properties: {
tokenId: { type: 'string', format: 'misskey:id' },
token: { type: 'string' },
},
required: ['tokenId'],
anyOf: [
{ required: ['tokenId'] },
{ required: ['token'] },
],
} as const;

@Injectable()
Expand All @@ -29,13 +33,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private accessTokensRepository: AccessTokensRepository,
) {
super(meta, paramDef, async (ps, me) => {
const tokenExist = await this.accessTokensRepository.exist({ where: { id: ps.tokenId } });
if (ps.tokenId) {
const tokenExist = await this.accessTokensRepository.exist({ where: { id: ps.tokenId } });

if (tokenExist) {
await this.accessTokensRepository.delete({
id: ps.tokenId,
userId: me.id,
});
if (tokenExist) {
await this.accessTokensRepository.delete({
id: ps.tokenId,
userId: me.id,
});
}
} else if (ps.token) {
const tokenExist = await this.accessTokensRepository.exist({ where: { token: ps.token } });

if (tokenExist) {
await this.accessTokensRepository.delete({
token: ps.token,
userId: me.id,
});
}
}
});
}
Expand Down
6 changes: 4 additions & 2 deletions packages/frontend/src/pages/settings/plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';

const plugins = ref(ColdDeviceStorage.get('plugins'));

function uninstall(plugin) {
async function uninstall(plugin) {
ColdDeviceStorage.set('plugins', plugins.value.filter(x => x.id !== plugin.id));
os.success();
await os.apiWithDialog('i/revoke-token', {
token: plugin.token,
});
nextTick(() => {
unisonReload();
});
Expand Down

0 comments on commit d061c97

Please sign in to comment.