Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: use get profile api v2

phamhieueb057cb19b3d
diff --git a/studio/data/profile/profile-query.ts b/studio/data/profile/profile-query.ts
index bd06b0965a9..7cbddd3e13c 100644
--- a/studio/data/profile/profile-query.ts
+++ b/studio/data/profile/profile-query.ts
@@ -4,7 +4,7 @@ import { API_URL } from 'lib/constants'
import { useCallback } from 'react'
import { profileKeys } from './keys'
import Telemetry from 'lib/telemetry'
-import { useRouter } from 'next/router'
+import { NextRouter, useRouter } from 'next/router'
import { useTelemetryProps } from 'common'
export type Profile = {
@@ -26,10 +26,7 @@ export type ProfileResponse = Profile
* Create profile for new user
* This will also need to send a sign_up event
*/
-async function createProfile() {
- const router = useRouter()
- const telemetryProps = useTelemetryProps()
-
+async function createProfile(router: NextRouter, telemetryProps: any) {
const response = await post(`${API_URL}/profile`, {})
if (response.error) {
throw response.error
@@ -45,14 +42,17 @@ async function createProfile() {
return response
}
-export async function getProfile(signal?: AbortSignal) {
+export async function getProfile(router: NextRouter, telemetryProps: any, signal?: AbortSignal) {
const response = await get(`${API_URL}/profile`, {
signal,
+ headers: {
+ Version: '2',
+ },
})
if (response.error) {
// if response.error is not found
// we need to send request to create new user profile
- if (response.error.code === 404) return await createProfile()
+ if (response.error.code === 404) return await createProfile(router, telemetryProps)
throw response.error
}
@@ -65,20 +65,28 @@ export type ProfileError = unknown
export const useProfileQuery = <TData = ProfileData>({
enabled = true,
...options
-}: UseQueryOptions<ProfileData, ProfileError, TData> = {}) =>
- useQuery<ProfileData, ProfileError, TData>(
+}: UseQueryOptions<ProfileData, ProfileError, TData> = {}) => {
+ const router = useRouter()
+ const telemetryProps = useTelemetryProps()
+
+ return useQuery<ProfileData, ProfileError, TData>(
profileKeys.profile(),
- ({ signal }) => getProfile(signal),
+ ({ signal }) => getProfile(router, telemetryProps, signal),
{
staleTime: 1000 * 60 * 30, // default good for 30 mins
...options,
}
)
+}
export const useProfilePrefetch = () => {
const client = useQueryClient()
+ const router = useRouter()
+ const telemetryProps = useTelemetryProps()
return useCallback(() => {
- client.prefetchQuery(profileKeys.profile(), ({ signal }) => getProfile(signal))
+ client.prefetchQuery(profileKeys.profile(), ({ signal }) =>
+ getProfile(router, telemetryProps, signal)
+ )
}, [])
}