mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 18:34:26 +08:00
22 lines
600 B
TypeScript
22 lines
600 B
TypeScript
import useSWR, { mutate } from 'swr'
|
|
import { get } from 'lib/common/fetch'
|
|
import { API_URL } from 'lib/constants'
|
|
|
|
export function useProjectAuthConfig(ref: string) {
|
|
const url = `${API_URL}/auth/${ref}/config`
|
|
const { data, error } = useSWR<any>(url, get)
|
|
const anyError = data?.error || error
|
|
|
|
function mutateAuthConfig(updatedConfig: any, revalidate?: boolean) {
|
|
mutate(url, { ...updatedConfig }, revalidate ?? true)
|
|
}
|
|
|
|
return {
|
|
config: anyError ? undefined : data,
|
|
error: anyError,
|
|
isLoading: !anyError && !data,
|
|
isError: !!anyError,
|
|
mutateAuthConfig,
|
|
}
|
|
}
|