1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Moving to JSON instead of FormData for oauth

This commit is contained in:
xmflsct
2023-01-09 16:44:11 +01:00
parent 1b2d9d144f
commit 1025d85ae5

View File

@ -1,9 +1,9 @@
import { import {
QueryFunctionContext, QueryFunctionContext,
useMutation, useMutation,
UseMutationOptions, UseMutationOptions,
useQuery, useQuery,
UseQueryOptions UseQueryOptions
} from '@tanstack/react-query' } from '@tanstack/react-query'
import apiGeneral from '@utils/api/general' import apiGeneral from '@utils/api/general'
import apiInstance from '@utils/api/instance' import apiInstance from '@utils/api/instance'
@ -29,24 +29,23 @@ const useAppsQuery = (
return useQuery(queryKey, queryFunctionApps, params?.options) return useQuery(queryKey, queryFunctionApps, params?.options)
} }
type MutationVarsApps = { domain: string } type MutationVarsApps = { domain: string; scopes: string[] }
export const redirectUri = AuthSession.makeRedirectUri({ export const redirectUri = AuthSession.makeRedirectUri({
native: 'tooot://instance-auth', native: 'tooot://instance-auth',
useProxy: false useProxy: false
}) })
const mutationFunctionApps = async ({ domain }: MutationVarsApps) => { const mutationFunctionApps = async ({ domain, scopes }: MutationVarsApps) => {
const formData = new FormData()
formData.append('client_name', 'tooot')
formData.append('website', 'https://tooot.app')
formData.append('redirect_uris', redirectUri)
formData.append('scopes', 'read write follow push')
return apiGeneral<Mastodon.Apps>({ return apiGeneral<Mastodon.Apps>({
method: 'post', method: 'post',
domain: domain, domain: domain,
url: `api/v1/apps`, url: 'api/v1/apps',
body: formData body: {
client_name: 'tooot',
website: 'https://tooot.app',
redirect_uris: redirectUri,
scopes: scopes.join(' ')
}
}).then(res => res.body) }).then(res => res.body)
} }