1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/utils/slices/instances/remove.ts
2021-03-01 00:28:14 +01:00

39 lines
1002 B
TypeScript

import { createAsyncThunk } from '@reduxjs/toolkit'
import * as AuthSession from 'expo-auth-session'
import { Instance } from '../instancesSlice'
import { updateInstancePush } from './updatePush'
const removeInstance = createAsyncThunk(
'instances/remove',
async (instance: Instance, { dispatch }): Promise<Instance> => {
if (instance.push.global.value) {
dispatch(updateInstancePush(false))
}
let revoked = undefined
try {
revoked = await AuthSession.revokeAsync(
{
clientId: instance.appData.clientId,
clientSecret: instance.appData.clientSecret,
token: instance.token,
scopes: ['read', 'write', 'follow', 'push']
},
{
revocationEndpoint: `https://${instance.url}/oauth/revoke`
}
)
} catch {
console.warn('Revoking error')
}
if (!revoked) {
console.warn('Revoking error')
}
return Promise.resolve(instance)
}
)
export default removeInstance