2
0
Files
bot/apps/builder/services/credentials.ts
2022-01-18 18:27:26 +01:00

23 lines
490 B
TypeScript

import { Credentials } from 'db'
import useSWR from 'swr'
import { fetcher } from './utils'
export const useCredentials = ({
userId,
onError,
}: {
userId?: string
onError: (error: Error) => void
}) => {
const { data, error, mutate } = useSWR<{ credentials: Credentials[] }, Error>(
userId ? `/api/users/${userId}/credentials` : null,
fetcher
)
if (error) onError(error)
return {
credentials: data?.credentials,
isLoading: !error && !data,
mutate,
}
}