Skip to content

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

fix: create new user profile

phamhieu108edf4dfeee
diff --git a/studio/data/profile/profile-query.ts b/studio/data/profile/profile-query.ts
index 479cb7233aa..63d16a441d7 100644
--- a/studio/data/profile/profile-query.ts
+++ b/studio/data/profile/profile-query.ts
@@ -1,8 +1,9 @@
import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
-import { get } from 'lib/common/fetch'
+import { get, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { useCallback } from 'react'
import { profileKeys } from './keys'
+import Telemetry from 'lib/telemetry'
export type Profile = {
id: number
@@ -19,11 +20,36 @@ export type Profile = {
export type ProfileResponse = Profile
+/**
+ * Create profile for new user
+ * This will also need to send a sign_up event
+ */
+async function createProfile() {
+ const response = await post(`${API_URL}/profile`, {})
+ if (response.error) {
+ throw response.error
+ }
+
+ Telemetry.sendEvent(
+ { category: 'conversion', action: 'sign_up', label: '' },
+ {
+ screenResolution:
+ typeof window !== 'undefined' ? `${window.innerWidth}x${window.innerHeight}` : undefined,
+ language: 'en-US',
+ }
+ )
+
+ return response
+}
+
export async function getProfile(signal?: AbortSignal) {
const response = await get(`${API_URL}/profile`, {
signal,
})
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()
throw response.error
}