mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
fix: create new user profile
This commit is contained in:
1 parent
57465f57ae
commit
108edf4dfe
1 file changed
+27
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user