Skip to content

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

adds profile context

Alaister Youngf45f5e4e0d25
diff --git a/package-lock.json b/package-lock.json
index 8f7cf61213f..0f30f1b8481 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -43397,8 +43397,6 @@
"@sentry/nextjs": "^6.17.4",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.25.0",
- "@supabase/auth-helpers-nextjs": "^0.5.6",
- "@supabase/auth-helpers-react": "^0.3.1",
"@supabase/react-data-grid": "^7.1.0-beta.7",
"@supabase/shared-types": "^0.1.43",
"@supabase/supabase-js": "^2.23.0",
diff --git a/studio/components/interfaces/App/CommandMenuWrapper.tsx b/studio/components/interfaces/App/CommandMenuWrapper.tsx
index b08467d59c3..c144d66e646 100644
--- a/studio/components/interfaces/App/CommandMenuWrapper.tsx
+++ b/studio/components/interfaces/App/CommandMenuWrapper.tsx
@@ -8,9 +8,9 @@ import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectConte
import { useProjectApiQuery } from 'data/config/project-api-query'
import { SqlSnippet } from 'data/content/sql-snippets-query'
import { useEntityDefinitionsQuery } from 'data/database/entity-definitions-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { checkPermissions, useFlag, useSelectedOrganization, useStore } from 'hooks'
import { uuidv4 } from 'lib/helpers'
+import { useProfile } from 'lib/profile'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
import { createSqlSnippetSkeleton } from '../SQLEditor/SQLEditor.utils'
@@ -25,7 +25,7 @@ const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
const allowCMDKDataOptIn = useFlag('dashboardCmdkDataOptIn')
const isOptedInToAI = opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const { data: settings } = useProjectApiQuery({ projectRef: ref })
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'sql', owner_id: profile?.id },
diff --git a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
index 89549bcc9c6..1f1335bc84d 100644
--- a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
@@ -10,8 +10,8 @@ import { useOrganizationDetailQuery } from 'data/organizations/organization-deta
import { useOrganizationMemberUpdateMutation } from 'data/organizations/organization-member-update-mutation'
import { useOrganizationRolesQuery } from 'data/organizations/organization-roles-query'
import { usePermissionsQuery } from 'data/permissions/permissions-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useSelectedOrganization, useStore } from 'hooks'
+import { useProfile } from 'lib/profile'
import { Member } from 'types'
import { Badge, Button, IconAlertCircle, IconLoader, IconUser, Listbox, Loading, Modal } from 'ui'
import { getUserDisplayName, isInviteExpired } from '../Organization.utils'
@@ -33,7 +33,7 @@ const MembersView = ({ searchString }: MembersViewProps) => {
const { slug } = useParams()
const selectedOrganization = useSelectedOrganization()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const { data: permissions } = usePermissionsQuery()
const { data: detailData, isLoading: isLoadingOrgDetails } = useOrganizationDetailQuery({ slug })
const { data: rolesData, isLoading: isLoadingRoles } = useOrganizationRolesQuery({ slug })
diff --git a/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx b/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
index 600ce662774..b490d2081cc 100644
--- a/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
@@ -7,10 +7,10 @@ import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmM
import { useOrganizationDetailQuery } from 'data/organizations/organization-detail-query'
import { useOrganizationRolesQuery } from 'data/organizations/organization-roles-query'
import { usePermissionsQuery } from 'data/permissions/permissions-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useSelectedOrganization, useStore } from 'hooks'
import { delete_ } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
+import { useProfile } from 'lib/profile'
import InviteMemberButton from './InviteMemberButton'
import MembersView from './MembersView'
import { hasMultipleOwners, useGetRolesManagementPermissions } from './TeamSettings.utils'
@@ -19,7 +19,7 @@ const TeamSettings = () => {
const { ui } = useStore()
const { slug } = useParams()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const selectedOrganization = useSelectedOrganization()
const isOwner = selectedOrganization?.is_owner
diff --git a/studio/components/interfaces/Reports/Reports.tsx b/studio/components/interfaces/Reports/Reports.tsx
index 5ab137f59b8..f08e517394c 100644
--- a/studio/components/interfaces/Reports/Reports.tsx
+++ b/studio/components/interfaces/Reports/Reports.tsx
@@ -1,8 +1,9 @@
-import { useEffect, useState } from 'react'
import * as Tooltip from '@radix-ui/react-tooltip'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import dayjs from 'dayjs'
import { groupBy, isNull } from 'lodash'
import { toJS } from 'mobx'
-import dayjs from 'dayjs'
+import { useEffect, useState } from 'react'
import {
Badge,
Button,
@@ -14,26 +15,25 @@ import {
IconSave,
IconSettings,
} from 'ui'
-import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { checkPermissions } from 'hooks'
import { useParams } from 'common/hooks'
-import { uuidv4 } from 'lib/helpers'
-import { METRIC_CATEGORIES, METRICS, TIME_PERIODS_REPORTS } from 'lib/constants'
-import { useProjectContentStore } from 'stores/projectContentStore'
-import Loading from 'components/ui/Loading'
import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'
+import Loading from 'components/ui/Loading'
import NoPermission from 'components/ui/NoPermission'
+import { useCheckPermissions } from 'hooks'
+import { METRIC_CATEGORIES, METRICS, TIME_PERIODS_REPORTS } from 'lib/constants'
+import { uuidv4 } from 'lib/helpers'
+import { useProfile } from 'lib/profile'
+import { useProjectContentStore } from 'stores/projectContentStore'
import GridResize from './GridResize'
import { LAYOUT_COLUMN_COUNT } from './Reports.constants'
-import { useProfileQuery } from 'data/profile/profile-query'
const DEFAULT_CHART_COLUMN_COUNT = 12
const DEFAULT_CHART_ROW_COUNT = 4
const Reports = () => {
const { id, ref } = useParams()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const [report, setReport] = useState<any>()
@@ -46,7 +46,7 @@ const Reports = () => {
const [endDate, setEndDate] = useState<any>(null)
const contentStore = useProjectContentStore(ref)
- const canReadReport = checkPermissions(PermissionAction.READ, 'user_content', {
+ const canReadReport = useCheckPermissions(PermissionAction.READ, 'user_content', {
resource: {
type: 'report',
visibility: report?.visibility,
@@ -54,7 +54,7 @@ const Reports = () => {
},
subject: { id: profile?.id },
})
- const canUpdateReport = checkPermissions(PermissionAction.UPDATE, 'user_content', {
+ const canUpdateReport = useCheckPermissions(PermissionAction.UPDATE, 'user_content', {
resource: {
type: 'report',
visibility: report?.visibility,
diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
index 1aa386bdac5..3c729c690d2 100644
--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
@@ -1,29 +1,29 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition } from 'lodash'
import { observer } from 'mobx-react-lite'
-import { PermissionAction } from '@supabase/shared-types/out/constants'
-import Telemetry from 'lib/telemetry'
-import { checkPermissions, useStore } from 'hooks'
+import { useParams, useTelemetryProps } from 'common'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'
-import SQLCard from './SQLCard'
-import { createSqlSnippetSkeleton } from '../SQLEditor.utils'
-import { useTelemetryProps, useParams } from 'common'
-import { useRouter } from 'next/router'
import { SqlSnippet } from 'data/content/sql-snippets-query'
-import { useProfileQuery } from 'data/profile/profile-query'
-import { useSqlEditorStateSnapshot } from 'state/sql-editor'
+import { useCheckPermissions, useStore } from 'hooks'
import { uuidv4 } from 'lib/helpers'
+import { useProfile } from 'lib/profile'
+import Telemetry from 'lib/telemetry'
+import { useRouter } from 'next/router'
+import { useSqlEditorStateSnapshot } from 'state/sql-editor'
+import { createSqlSnippetSkeleton } from '../SQLEditor.utils'
+import SQLCard from './SQLCard'
const SQLTemplates = observer(() => {
const { ui } = useStore()
const { ref } = useParams()
const router = useRouter()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const [sql, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })
const telemetryProps = useTelemetryProps()
const snap = useSqlEditorStateSnapshot()
- const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
+ const canCreateSQLSnippet = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'sql', owner_id: profile?.id },
subject: { id: profile?.id },
})
diff --git a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
index 3f20bd4a7c5..8687e36e43e 100644
--- a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
@@ -1,20 +1,20 @@
-import { Button, Dropdown, IconChevronDown, IconPlay, Badge, Popover, Alert } from 'ui'
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { Alert, Badge, Button, Dropdown, IconChevronDown, IconPlay, Popover } from 'ui'
+import { useCheckPermissions } from 'hooks'
+import { IS_PLATFORM } from 'lib/constants'
+import { useProfile } from 'lib/profile'
+import Link from 'next/link'
+import React from 'react'
import {
EXPLORER_DATEPICKER_HELPERS,
- LogsTableName,
- LogsWarning,
LOGS_SOURCE_DESCRIPTION,
LogTemplate,
+ LogsTableName,
+ LogsWarning,
} from '.'
import DatePickers from './Logs.DatePickers'
-import Link from 'next/link'
-import React from 'react'
-import { checkPermissions } from 'hooks'
-import { IS_PLATFORM } from 'lib/constants'
-import { useProfileQuery } from 'data/profile/profile-query'
export interface LogsQueryPanelProps {
templates?: LogTemplate[]
@@ -45,8 +45,8 @@ const LogsQueryPanel = ({
onDateChange,
warnings,
}: LogsQueryPanelProps) => {
- const { data: profile } = useProfileQuery()
- const canCreateLogQuery = checkPermissions(PermissionAction.CREATE, 'user_content', {
+ const { profile } = useProfile()
+ const canCreateLogQuery = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'log_sql', owner_id: profile?.id },
subject: { id: profile?.id },
})
diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsx
index f3cb3f15ed1..3bec0ff1722 100644
--- a/studio/components/interfaces/Support/SupportForm.tsx
+++ b/studio/components/interfaces/Support/SupportForm.tsx
@@ -1,7 +1,7 @@
import { CLIENT_LIBRARIES } from 'common/constants'
import { observer } from 'mobx-react-lite'
import Link from 'next/link'
-import { ChangeEvent, FC, useEffect, useRef, useState } from 'react'
+import { ChangeEvent, useEffect, useRef, useState } from 'react'
import {
Button,
Checkbox,
@@ -22,7 +22,6 @@ import InformationBox from 'components/ui/InformationBox'
import Connecting from 'components/ui/Loading'
import MultiSelect from 'components/ui/MultiSelect'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useProjectsQuery } from 'data/projects/projects-query'
import { useProjectSubscriptionV2Query } from 'data/subscriptions/project-subscription-v2-query'
import { useFlag, useStore } from 'hooks'
@@ -30,6 +29,7 @@ import useLatest from 'hooks/misc/useLatest'
import { get, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { detectBrowser } from 'lib/helpers'
+import { useProfile } from 'lib/profile'
import { Project } from 'types'
import DisabledStateForFreeTier from './DisabledStateForFreeTier'
import { CATEGORY_OPTIONS, SERVICE_OPTIONS, SEVERITY_OPTIONS } from './Support.constants'
@@ -37,11 +37,11 @@ import { formatMessage, uploadAttachments } from './SupportForm.utils'
const MAX_ATTACHMENTS = 5
-interface Props {
+export interface SupportFormProps {
setSentCategory: (value: string) => void
}
-const SupportForm: FC<Props> = ({ setSentCategory }) => {
+const SupportForm = ({ setSentCategory }: SupportFormProps) => {
const { ui } = useStore()
const { ref, subject, category, message } = useParams()
@@ -75,7 +75,7 @@ const SupportForm: FC<Props> = ({ setSentCategory }) => {
}
}, [uploadedFiles])
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const respondToEmail = profile?.primary_email ?? 'your email'
if (!isInitialized) {
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index 1ae369e77f9..d23ab9333c0 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -1,41 +1,28 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition } from 'lodash'
-import { useState, useMemo } from 'react'
import { observer } from 'mobx-react-lite'
-import {
- Button,
- Menu,
- Input,
- IconSearch,
- IconPlus,
- IconX,
- Dropdown,
- IconChevronDown,
- useCommandMenu,
- IconCode,
- AiIcon,
-} from 'ui'
-import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useRouter } from 'next/router'
+import { useMemo, useState } from 'react'
-import { checkPermissions, useFlag, useStore } from 'hooks'
+import { useParams } from 'common'
+import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEditor.utils'
+import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import { SqlSnippet, useSqlSnippetsQuery } from 'data/content/sql-snippets-query'
+import { useCheckPermissions, useFlag, useStore } from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
import { uuidv4 } from 'lib/helpers'
-
-import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'
-import { useParams } from 'common'
+import { useProfile } from 'lib/profile'
import { useSnippets, useSqlEditorStateSnapshot } from 'state/sql-editor'
-import { SqlSnippet, useSqlSnippetsQuery } from 'data/content/sql-snippets-query'
-import { useProfileQuery } from 'data/profile/profile-query'
-import ShimmeringLoader from 'components/ui/ShimmeringLoader'
-import QueryItem from './QueryItem'
-import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEditor.utils'
-import { useRouter } from 'next/router'
+import { Button, Dropdown, IconPlus, IconSearch, IconX, Input, Menu, useCommandMenu } from 'ui'
import { COMMAND_ROUTES } from 'ui/src/components/Command/Command.constants'
+import QueryItem from './QueryItem'
const SideBarContent = observer(() => {
const { ui } = useStore()
const { ref, id } = useParams()
const router = useRouter()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const [filterString, setFilterString] = useState('')
const { setPages, setIsOpen } = useCommandMenu()
const showCmdkHelper = useFlag('dashboardCmdk')
@@ -63,7 +50,7 @@ const SideBarContent = observer(() => {
filterString.length === 0
? queries
: queries.filter((tab) => tab.name.toLowerCase().includes(filterString.toLowerCase()))
- const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
+ const canCreateSQLSnippet = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'sql', owner_id: profile?.id },
subject: { id: profile?.id },
})
diff --git a/studio/lib/auth.tsx b/studio/lib/auth.tsx
index fba39ed3aac..a0e3e21ed7a 100644
--- a/studio/lib/auth.tsx
+++ b/studio/lib/auth.tsx
@@ -8,9 +8,6 @@ import {
gotrueClient,
useTelemetryProps,
} from 'common'
-import { invalidateOrganizationsQuery } from 'data/organizations/organizations-query'
-import { useProfileCreateMutation } from 'data/profile/profile-create-mutation'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useStore } from 'hooks'
import Telemetry from 'lib/telemetry'
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
@@ -57,37 +54,6 @@ export const AuthProvider = ({ children }: PropsWithChildren<{}>) => {
return subscription.unsubscribe
}, [])
- const { mutate: createProfile } = useProfileCreateMutation({
- async onSuccess() {
- Telemetry.sendEvent(
- { category: 'conversion', action: 'sign_up', label: '' },
- telemetryProps,
- router
- )
-
- await invalidateOrganizationsQuery(queryClient)
- },
- onError(err) {
- ui.setNotification({
- category: 'error',
- message: 'Failed to create your profile. Please refresh to try again.',
- })
- },
- })
-
- // Track telemetry for the current user
- useProfileQuery({
- onSuccess(profile) {
- Telemetry.sendIdentify(profile, telemetryProps)
- },
- onError(err) {
- // if the user does not yet exist, create a profile for them
- if (typeof err === 'object' && err !== null && 'code' in err && (err as any).code === 404) {
- createProfile()
- }
- },
- })
-
return <AuthProviderInternal alwaysLoggedIn={!IS_PLATFORM}>{children}</AuthProviderInternal>
}
diff --git a/studio/lib/profile.tsx b/studio/lib/profile.tsx
new file mode 100644
index 00000000000..6d38af7af4d
--- /dev/null
+++ b/studio/lib/profile.tsx
@@ -0,0 +1,72 @@
+import { useQueryClient } from '@tanstack/react-query'
+import { useRouter } from 'next/router'
+import { PropsWithChildren, createContext, useContext, useMemo } from 'react'
+
+import { useTelemetryProps } from 'common'
+import { invalidateOrganizationsQuery } from 'data/organizations/organizations-query'
+import { useProfileCreateMutation } from 'data/profile/profile-create-mutation'
+import { useProfileQuery } from 'data/profile/profile-query'
+import { Profile } from 'data/profile/types'
+import { useStore } from 'hooks'
+import Telemetry from 'lib/telemetry'
+
+export type ProfileContextType = {
+ profile: Profile | undefined
+ isLoading: boolean
+}
+
+export const ProfileContext = createContext<ProfileContextType>({
+ profile: undefined,
+ isLoading: true,
+})
+
+export const ProfileProvider = ({ children }: PropsWithChildren<{}>) => {
+ const queryClient = useQueryClient()
+ const { ui } = useStore()
+ const router = useRouter()
+ const telemetryProps = useTelemetryProps()
+
+ const { mutate: createProfile, isLoading: isCreating } = useProfileCreateMutation({
+ async onSuccess() {
+ Telemetry.sendEvent(
+ { category: 'conversion', action: 'sign_up', label: '' },
+ telemetryProps,
+ router
+ )
+
+ await invalidateOrganizationsQuery(queryClient)
+ },
+ onError(err) {
+ ui.setNotification({
+ category: 'error',
+ message: 'Failed to create your profile. Please refresh to try again.',
+ })
+ },
+ })
+
+ // Track telemetry for the current user
+ const { data: profile, isLoading: isLoadingProfile } = useProfileQuery({
+ onSuccess(profile) {
+ Telemetry.sendIdentify(profile, telemetryProps)
+ },
+ onError(err) {
+ // if the user does not yet exist, create a profile for them
+ if (typeof err === 'object' && err !== null && 'code' in err && (err as any).code === 404) {
+ createProfile()
+ }
+ },
+ })
+
+ const value = useMemo(() => {
+ const isLoading = isLoadingProfile || isCreating
+
+ return {
+ profile,
+ isLoading,
+ }
+ }, [isLoadingProfile, isCreating, profile])
+
+ return <ProfileContext.Provider value={value}>{children}</ProfileContext.Provider>
+}
+
+export const useProfile = () => useContext(ProfileContext)
diff --git a/studio/package.json b/studio/package.json
index a00f3be6e84..082dc8629f3 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -29,8 +29,6 @@
"@sentry/nextjs": "^6.17.4",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.25.0",
- "@supabase/auth-helpers-nextjs": "^0.5.6",
- "@supabase/auth-helpers-react": "^0.3.1",
"@supabase/react-data-grid": "^7.1.0-beta.7",
"@supabase/shared-types": "^0.1.43",
"@supabase/supabase-js": "^2.23.0",
diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsx
index 7f707309d29..dcd734d21b9 100644
--- a/studio/pages/_app.tsx
+++ b/studio/pages/_app.tsx
@@ -28,13 +28,14 @@ import Head from 'next/head'
import { AppPropsWithLayout } from 'types'
import { ThemeProvider } from 'common'
-import { useEffect, useMemo, useState } from 'react'
+import { useEffect, useState } from 'react'
import { Hydrate, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { RootStore } from 'stores'
import HCaptchaLoadedStore from 'stores/hcaptcha-loaded-store'
import { StoreProvider } from 'hooks'
import { AuthProvider } from 'lib/auth'
+import { ProfileProvider } from 'lib/profile'
import { dart } from 'lib/constants/prism'
import { useRootQueryClient } from 'data/query-client'
@@ -51,7 +52,6 @@ import useAutoAuthRedirect from 'hooks/misc/useAutoAuthRedirect'
import { TooltipProvider } from '@radix-ui/react-tooltip'
import Favicons from 'components/head/Favicons'
import { IS_PLATFORM } from 'lib/constants'
-import { SessionContextProvider } from '@supabase/auth-helpers-react'
import { createClient } from '@supabase/supabase-js'
dayjs.extend(customParseFormat)
@@ -110,51 +110,39 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
const getLayout = Component.getLayout ?? ((page) => page)
- const AuthContainer = useMemo(
- () => (props: any) => {
- return IS_PLATFORM ? (
- <SessionContextProvider supabaseClient={supabase as any}>
- <AuthProvider>{props.children}</AuthProvider>
- </SessionContextProvider>
- ) : (
- <AuthProvider>{props.children}</AuthProvider>
- )
- },
- [supabase]
- )
- //
-
return (
<QueryClientProvider client={queryClient}>
<Hydrate state={pageProps.dehydratedState}>
<StoreProvider rootStore={rootStore}>
- <AuthContainer>
- <FlagProvider>
- <Head>
- <title>Supabase</title>
- <meta name="viewport" content="initial-scale=1.0, width=device-width" />
- </Head>
- <Favicons />
-
- <PageTelemetry>
- <TooltipProvider>
- <RouteValidationWrapper>
- <ThemeProvider>
- <CommandMenuWrapper>
- <AppBannerWrapper>
- {getLayout(<Component {...pageProps} />)}
- </AppBannerWrapper>
- </CommandMenuWrapper>
- </ThemeProvider>
- </RouteValidationWrapper>
- </TooltipProvider>
- </PageTelemetry>
-
- <HCaptchaLoadedStore />
- <PortalToast />
- <ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
- </FlagProvider>
- </AuthContainer>
+ <AuthProvider>
+ <ProfileProvider>
+ <FlagProvider>
+ <Head>
+ <title>Supabase</title>
+ <meta name="viewport" content="initial-scale=1.0, width=device-width" />
+ </Head>
+ <Favicons />
+
+ <PageTelemetry>
+ <TooltipProvider>
+ <RouteValidationWrapper>
+ <ThemeProvider>
+ <CommandMenuWrapper>
+ <AppBannerWrapper>
+ {getLayout(<Component {...pageProps} />)}
+ </AppBannerWrapper>
+ </CommandMenuWrapper>
+ </ThemeProvider>
+ </RouteValidationWrapper>
+ </TooltipProvider>
+ </PageTelemetry>
+
+ <HCaptchaLoadedStore />
+ <PortalToast />
+ <ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
+ </FlagProvider>
+ </ProfileProvider>
+ </AuthProvider>
</StoreProvider>
</Hydrate>
</QueryClientProvider>
diff --git a/studio/pages/account/me.tsx b/studio/pages/account/me.tsx
index 2ecbc5de734..0484fd25730 100644
--- a/studio/pages/account/me.tsx
+++ b/studio/pages/account/me.tsx
@@ -1,17 +1,17 @@
import { observer } from 'mobx-react-lite'
-import { Button, IconMoon, IconSun, Input, Listbox } from 'ui'
+import Link from 'next/link'
+import { useTheme } from 'common'
import { AccountLayout } from 'components/layouts'
import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'
import Panel from 'components/ui/Panel'
-import { Profile as ProfileType } from 'data/profile/types'
import { useProfileUpdateMutation } from 'data/profile/profile-update-mutation'
-import { useProfileQuery } from 'data/profile/profile-query'
+import { Profile as ProfileType } from 'data/profile/types'
import { useStore } from 'hooks'
import { useSession } from 'lib/auth'
-import Link from 'next/link'
+import { useProfile } from 'lib/profile'
import { NextPageWithLayout } from 'types'
-import { useTheme } from 'common'
+import { Button, IconMoon, IconSun, Input, Listbox } from 'ui'
const User: NextPageWithLayout = () => {
return (
@@ -41,7 +41,7 @@ const ProfileCard = observer(() => {
const { ui } = useStore()
const { mutateAsync } = useProfileUpdateMutation()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
// TODO: ^ handle loading state
const updateUser = async (model: any) => {
diff --git a/studio/pages/join/index.tsx b/studio/pages/join/index.tsx
index cbfc23909ae..0f1a5a1f364 100644
--- a/studio/pages/join/index.tsx
+++ b/studio/pages/join/index.tsx
@@ -6,11 +6,11 @@ import { Button, IconCheckSquare, Loading } from 'ui'
import { useParams } from 'common'
import { invalidateOrganizationsQuery } from 'data/organizations/organizations-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useStore } from 'hooks'
import { useSignOut } from 'lib/auth'
import { delete_, get, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
+import { useProfile } from 'lib/profile'
interface ITokenInfo {
organization_name?: string | undefined
@@ -28,7 +28,7 @@ const JoinOrganizationPage = () => {
const router = useRouter()
const { slug, token, name } = useParams()
const { ui } = useStore()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const signOut = useSignOut()
const [isSubmitting, setIsSubmitting] = useState(false)
diff --git a/studio/pages/project/[ref]/reports/index.tsx b/studio/pages/project/[ref]/reports/index.tsx
index 7281b26a1c3..7449cac1495 100644
--- a/studio/pages/project/[ref]/reports/index.tsx
+++ b/studio/pages/project/[ref]/reports/index.tsx
@@ -8,10 +8,10 @@ import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectConte
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
import { createReport } from 'components/to-be-cleaned/Reports/Reports.utils'
import Loading from 'components/ui/Loading'
-import { useProfileQuery } from 'data/profile/profile-query'
-import { checkPermissions, useFlag, useStore } from 'hooks'
+import { useCheckPermissions, useFlag, useStore } from 'hooks'
import { post } from 'lib/common/fetch'
import { API_URL, PROJECT_STATUS } from 'lib/constants'
+import { useProfile } from 'lib/profile'
import { useProjectContentStore } from 'stores/projectContentStore'
import { NextPageWithLayout } from 'types'
@@ -21,12 +21,12 @@ export const UserReportPage: NextPageWithLayout = () => {
const router = useRouter()
const { ref } = useParams()
- const { data: profile } = useProfileQuery()
+ const { profile } = useProfile()
const { ui } = useStore()
const { project } = useProjectContext()
const contentStore = useProjectContentStore(ref)
- const canCreateReport = checkPermissions(PermissionAction.CREATE, 'user_content', {
+ const canCreateReport = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'report', owner_id: profile?.id },
subject: { id: profile?.id },
})
diff --git a/studio/pages/projects.tsx b/studio/pages/projects.tsx
index 6b7ceaae83d..f19254d4c47 100644
--- a/studio/pages/projects.tsx
+++ b/studio/pages/projects.tsx
@@ -3,24 +3,18 @@ import { AccountLayout } from 'components/layouts'
import OrganizationDropdown from 'components/to-be-cleaned/Dropdown/OrganizationDropdown'
import Connecting from 'components/ui/Loading/Loading'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
-import { useProfileQuery } from 'data/profile/profile-query'
import { useAutoProjectsPrefetch } from 'data/projects/projects-query'
import { IS_PLATFORM } from 'lib/constants'
+import { useProfile } from 'lib/profile'
import { NextPageWithLayout } from 'types'
const ProjectsPage: NextPageWithLayout = () => {
- const {
- data: organizations,
- isLoading: _isLoading,
- isSuccess: isOrganizationSuccess,
- } = useOrganizationsQuery()
+ const { data: organizations, isLoading: isOrganizationLoading } = useOrganizationsQuery()
useAutoProjectsPrefetch()
- const { isSuccess: isProfileCreated, isLoading: isProfileLoading } = useProfileQuery()
+ const { isLoading: isProfileLoading } = useProfile()
- // We'll continue the loading state if there's no organizations
- // because we're waiting for the default organization to be created
- const isLoading = _isLoading || isProfileLoading || !isOrganizationSuccess || !isProfileCreated
+ const isLoading = isOrganizationLoading || isProfileLoading
return (
<>