Skip to content

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

swap userUser() to useProfileQuery()

Alaister Young1c5d32d6d864
diff --git a/studio/components/interfaces/Organization/TeamSettings/InviteMemberButton.tsx b/studio/components/interfaces/Organization/TeamSettings/InviteMemberButton.tsx
index 3fd9caa0ea2..8dd437ebe3d 100644
--- a/studio/components/interfaces/Organization/TeamSettings/InviteMemberButton.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/InviteMemberButton.tsx
@@ -10,7 +10,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useOrganizationMemberInviteCreateMutation } from 'data/organizations/organization-member-invite-create-mutation'
export interface InviteMemberButtonProps {
- userId: string
+ userId: number
members: Member[]
roles: Role[]
rolesAddable: Number[]
@@ -70,7 +70,7 @@ const InviteMemberButton = ({
const response = await mutateAsync({
slug,
invitedEmail: values.email.toLowerCase(),
- ownerId: Number(userId),
+ ownerId: userId,
roleId,
})
diff --git a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
index 565d088ccad..f9e5e0b40ed 100644
--- a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx
@@ -8,7 +8,7 @@ import { Member, Role } from 'types'
import { useStore, useParams } from 'hooks'
import { isInviteExpired, getUserDisplayName } from '../Organization.utils'
-import { useUser } from 'lib/auth'
+import { useProfileQuery } from 'data/profile/profile-query'
import { useOrganizationMemberUpdateMutation } from 'data/organizations/organization-member-update-mutation'
import Table from 'components/to-be-cleaned/Table'
import MemberActions from './MemberActions'
@@ -30,7 +30,7 @@ const MembersView = ({ searchString, roles, members }: MembersViewProps) => {
const { ui } = useStore()
const { slug } = useParams()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const { rolesAddable, rolesRemovable } = getRolesManagementPermissions(roles)
@@ -109,7 +109,7 @@ const MembersView = ({ searchString, roles, members }: MembersViewProps) => {
...filteredMembers.map((x: Member, i: number) => {
const [memberRoleId] = x.role_ids ?? []
const role = (roles || []).find((role) => role.id === memberRoleId)
- const memberIsUser = x.primary_email == user?.email
+ const memberIsUser = x.primary_email == profile?.primary_email
const memberIsPendingInvite = !!x.invited_id
const canRemoveRole = rolesRemovable.includes(memberRoleId)
const disableRoleEdit = !canRemoveRole || memberIsUser || memberIsPendingInvite
diff --git a/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx b/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
index e086dde32f1..9289a210943 100644
--- a/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
@@ -5,8 +5,8 @@ import * as Tooltip from '@radix-ui/react-tooltip'
import { useStore, useParams } from 'hooks'
import { post } from 'lib/common/fetch'
-import { useUser } from 'lib/auth'
import { API_URL } from 'lib/constants'
+import { useProfileQuery } from 'data/profile/profile-query'
import InviteMemberButton from './InviteMemberButton'
import MembersView from './MembersView'
import { getRolesManagementPermissions, hasMultipleOwners } from './TeamSettings.utils'
@@ -18,7 +18,7 @@ const TeamSettings = () => {
const { ui } = useStore()
const { slug } = useParams()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const isOwner = ui.selectedOrganization?.is_owner
const { data: detailData } = useOrganizationDetailQuery({ slug })
@@ -74,10 +74,10 @@ const TeamSettings = () => {
placeholder="Filter members"
/>
<div className="flex items-center space-x-4">
- {canAddMembers && user !== null && (
+ {canAddMembers && profile !== undefined && (
<div>
<InviteMemberButton
- userId={user.id}
+ userId={profile.id}
members={members}
roles={roles}
rolesAddable={rolesAddable}
diff --git a/studio/components/interfaces/Reports/Reports.tsx b/studio/components/interfaces/Reports/Reports.tsx
index d08e16ce8c2..ec43b8041ec 100644
--- a/studio/components/interfaces/Reports/Reports.tsx
+++ b/studio/components/interfaces/Reports/Reports.tsx
@@ -20,19 +20,19 @@ import { checkPermissions, useParams } from 'hooks'
import { uuidv4 } from 'lib/helpers'
import { METRIC_CATEGORIES, METRICS, TIME_PERIODS_REPORTS } from 'lib/constants'
import { useProjectContentStore } from 'stores/projectContentStore'
+import { useProfileQuery } from 'data/profile/profile-query'
import Loading from 'components/ui/Loading'
import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'
import NoPermission from 'components/ui/NoPermission'
import GridResize from './GridResize'
import { LAYOUT_COLUMN_COUNT } from './Reports.constants'
-import { useUser } from 'lib/auth'
const DEFAULT_CHART_COLUMN_COUNT = 12
const DEFAULT_CHART_ROW_COUNT = 4
const Reports = () => {
const { id, ref } = useParams()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const [report, setReport] = useState<any>()
@@ -51,7 +51,7 @@ const Reports = () => {
visibility: report?.visibility,
owner_id: report?.owner_id,
},
- subject: { id: user?.id },
+ subject: { id: profile?.id },
})
const canUpdateReport = checkPermissions(PermissionAction.UPDATE, 'user_content', {
resource: {
@@ -59,7 +59,7 @@ const Reports = () => {
visibility: report?.visibility,
owner_id: report?.owner_id,
},
- subject: { id: user?.id },
+ subject: { id: profile?.id },
})
/*
diff --git a/studio/components/interfaces/SQLEditor/TabSqlQuery/FavouriteButton.tsx b/studio/components/interfaces/SQLEditor/TabSqlQuery/FavouriteButton.tsx
index 6935aa23eff..59cd87f4141 100644
--- a/studio/components/interfaces/SQLEditor/TabSqlQuery/FavouriteButton.tsx
+++ b/studio/components/interfaces/SQLEditor/TabSqlQuery/FavouriteButton.tsx
@@ -4,13 +4,13 @@ import { Button, IconHeart } from 'ui'
import * as Tooltip from '@radix-ui/react-tooltip'
import { useStore } from 'hooks'
-import { useUser } from 'lib/auth'
import Telemetry from 'lib/telemetry'
+import { useProfileQuery } from 'data/profile/profile-query'
import { useSqlStore } from 'localStores/sqlEditor/SqlEditorStore'
const FavouriteButton = () => {
const { ui, content: contentStore } = useStore()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const sqlEditorStore: any = useSqlStore()
@@ -53,7 +53,7 @@ const FavouriteButton = () => {
/*
* reload sql data in store and re-select tab
*/
- sqlEditorStore.loadTabs(sqlEditorStore.tabsFromContentStore(contentStore, user?.id), false)
+ sqlEditorStore.loadTabs(sqlEditorStore.tabsFromContentStore(contentStore, profile?.id), false)
sqlEditorStore.selectTab(id)
setLoading(false)
@@ -94,7 +94,7 @@ const FavouriteButton = () => {
/*
* reload sql data in store and re-select tab
*/
- sqlEditorStore.loadTabs(sqlEditorStore.tabsFromContentStore(contentStore, user?.id), false)
+ sqlEditorStore.loadTabs(sqlEditorStore.tabsFromContentStore(contentStore, profile?.id), false)
sqlEditorStore.selectTab(id)
setLoading(false)
} catch (error: any) {
diff --git a/studio/components/interfaces/SQLEditor/TabSqlQuery/UtilityActions.tsx b/studio/components/interfaces/SQLEditor/TabSqlQuery/UtilityActions.tsx
index c2d70f4bbff..fa06f309151 100644
--- a/studio/components/interfaces/SQLEditor/TabSqlQuery/UtilityActions.tsx
+++ b/studio/components/interfaces/SQLEditor/TabSqlQuery/UtilityActions.tsx
@@ -4,7 +4,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useKeyboardShortcuts, checkPermissions } from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
-import { useUser } from 'lib/auth'
+import { useProfileQuery } from 'data/profile/profile-query'
import { useSqlStore } from 'localStores/sqlEditor/SqlEditorStore'
import SavingIndicator from './SavingIndicator'
import FavouriteButton from './FavouriteButton'
@@ -15,12 +15,12 @@ export interface UtilityActionsProps {
}
const UtilityActions = ({ updateSqlSnippet }: UtilityActionsProps) => {
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const sqlEditorStore: any = useSqlStore()
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'sql', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'sql', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
useKeyboardShortcuts(
diff --git a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
index f9e8a6e3c52..3707cf06f8d 100644
--- a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
@@ -13,7 +13,7 @@ import DatePickers from './Logs.DatePickers'
import Link from 'next/link'
import React from 'react'
import { checkPermissions } from 'hooks'
-import { useUser } from 'lib/auth'
+import { useProfileQuery } from 'data/profile/profile-query'
export interface LogsQueryPanelProps {
templates?: LogTemplate[]
@@ -44,10 +44,10 @@ const LogsQueryPanel = ({
onDateChange,
warnings,
}: LogsQueryPanelProps) => {
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const canCreateLogQuery = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'log_sql', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'log_sql', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
return (
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
index c12857e8962..bee4b202877 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
@@ -2,7 +2,7 @@ import { ReactNode, useEffect } from 'react'
import { observer } from 'mobx-react-lite'
import { useStore, withAuth } from 'hooks'
-import { useUser } from 'lib/auth'
+import { useProfileQuery } from 'data/profile/profile-query'
import Error from 'components/ui/Error'
import { useSqlEditorStore, SqlEditorContext } from 'localStores/sqlEditor/SqlEditorStore'
import ProjectLayout from '../ProjectLayout/ProjectLayout'
@@ -15,14 +15,14 @@ export interface SQLEditorLayoutProps {
const SQLEditorLayout = ({ title, children }: SQLEditorLayoutProps) => {
const { ui, content, meta } = useStore()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const sqlEditorStore = useSqlEditorStore(ui.selectedProject?.ref, meta)
useEffect(() => {
if (sqlEditorStore) {
// this calls content.load() for us, as well as loading tabs
- sqlEditorStore.loadRemotePersistentData(content, user?.id)
+ sqlEditorStore.loadRemotePersistentData(content, profile?.id)
}
}, [sqlEditorStore])
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index 142b6c018de..699839ab3df 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -17,10 +17,10 @@ import {
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useOptimisticSqlSnippetCreate, useStore, checkPermissions } from 'hooks'
-import { useUser } from 'lib/auth'
import { IS_PLATFORM } from 'lib/constants'
import QueryTab from 'localStores/sqlEditor/QueryTab'
import { useSqlStore, TAB_TYPES } from 'localStores/sqlEditor/SqlEditorStore'
+import { useProfileQuery } from 'data/profile/profile-query'
import RenameQuery from 'components/to-be-cleaned/SqlEditor/RenameQuery'
import ConfirmationModal from 'components/ui/ConfirmationModal'
@@ -46,7 +46,7 @@ const OpenQueryItem = observer(
)
const DropdownMenu = observer(({ tabInfo }: { tabInfo: QueryTab }) => {
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const { content: contentStore } = useStore()
const sqlEditorStore: any = useSqlStore()
@@ -113,7 +113,7 @@ const DropdownMenu = observer(({ tabInfo }: { tabInfo: QueryTab }) => {
await contentStore.del(id)
sqlEditorStore.loadTabs(
- sqlEditorStore.tabsFromContentStore(contentStore, user?.id),
+ sqlEditorStore.tabsFromContentStore(contentStore, profile?.id),
false
)
}}
@@ -128,13 +128,13 @@ const DropdownMenu = observer(({ tabInfo }: { tabInfo: QueryTab }) => {
})
const SideBarContent = observer(() => {
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const sqlEditorStore: any = useSqlStore()
const [filterString, setFilterString] = useState('')
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'sql', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'sql', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
const handleNewQuery = useOptimisticSqlSnippetCreate(canCreateSQLSnippet)
diff --git a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
index d43f2827bf3..4c16b6571b7 100644
--- a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
+++ b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
@@ -10,16 +10,16 @@ import { Button, Dropdown, IconCheck, IconChevronDown, IconClipboard } from 'ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useKeyboardShortcuts, useStore, useWindowDimensions, checkPermissions } from 'hooks'
-import { useUser } from 'lib/auth'
import Telemetry from 'lib/telemetry'
import { copyToClipboard, timeout } from 'lib/helpers'
+import { useProfileQuery } from 'data/profile/profile-query'
import { useSqlStore, UTILITY_TAB_TYPES } from 'localStores/sqlEditor/SqlEditorStore'
import { SQL_SNIPPET_SCHEMA_VERSION } from './SqlEditor.constants'
import UtilityActions from 'components/interfaces/SQLEditor/TabSqlQuery/UtilityActions'
const TabSqlQuery = observer(() => {
const sqlEditorStore = useSqlStore()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const { content: contentStore } = useStore()
const { height: screenHeight } = useWindowDimensions()
@@ -29,8 +29,8 @@ const TabSqlQuery = observer(() => {
const offset = 3
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'sql', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'sql', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
useEffect(() => {
diff --git a/studio/components/to-be-cleaned/SqlEditor/TabWelcome.js b/studio/components/to-be-cleaned/SqlEditor/TabWelcome.js
index bcefdaee6de..5ca96a1c348 100644
--- a/studio/components/to-be-cleaned/SqlEditor/TabWelcome.js
+++ b/studio/components/to-be-cleaned/SqlEditor/TabWelcome.js
@@ -3,19 +3,19 @@ import { partition } from 'lodash'
import { observer } from 'mobx-react-lite'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useUser } from 'lib/auth'
import Telemetry from 'lib/telemetry'
import { useOptimisticSqlSnippetCreate, checkPermissions, useStore } from 'hooks'
+import { useProfileQuery } from 'data/profile/profile-query'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'
import CardButton from 'components/ui/CardButton'
const TabWelcome = observer(() => {
const { ui } = useStore()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const [sql, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'sql', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'sql', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
const handleNewQuery = useOptimisticSqlSnippetCreate(canCreateSQLSnippet)
diff --git a/studio/data/profile/profile-query.ts b/studio/data/profile/profile-query.ts
index d48256ef0d3..479cb7233aa 100644
--- a/studio/data/profile/profile-query.ts
+++ b/studio/data/profile/profile-query.ts
@@ -40,7 +40,10 @@ export const useProfileQuery = <TData = ProfileData>({
useQuery<ProfileData, ProfileError, TData>(
profileKeys.profile(),
({ signal }) => getProfile(signal),
- options
+ {
+ staleTime: 1000 * 60 * 30, // default good for 30 mins
+ ...options,
+ }
)
export const useProfilePrefetch = () => {
diff --git a/studio/hooks/misc/useOptimisticSqlSnippetCreate.ts b/studio/hooks/misc/useOptimisticSqlSnippetCreate.ts
index 6b5b48b264b..8791a61ee86 100644
--- a/studio/hooks/misc/useOptimisticSqlSnippetCreate.ts
+++ b/studio/hooks/misc/useOptimisticSqlSnippetCreate.ts
@@ -1,12 +1,12 @@
import { createSqlSnippetSkeleton } from 'components/to-be-cleaned/SqlEditor/SqlEditor.utils'
-import { useUser } from 'lib/auth'
+import { useProfileQuery } from 'data/profile/profile-query'
import { useSqlStore } from 'localStores/sqlEditor/SqlEditorStore'
import { useCallback } from 'react'
import { useStore } from './useStore'
export function useOptimisticSqlSnippetCreate(canCreateSQLSnippet: boolean) {
const { ui, content: contentStore } = useStore()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const sqlEditorStore: any = useSqlStore()
@@ -16,7 +16,7 @@ export function useOptimisticSqlSnippetCreate(canCreateSQLSnippet: boolean) {
const previouslySelectedTabId = sqlEditorStore.selectedTabId
const snippet = createSqlSnippetSkeleton({
- owner_id: user ? Number(user.id) : undefined,
+ owner_id: profile?.id,
...args,
})
@@ -24,7 +24,7 @@ export function useOptimisticSqlSnippetCreate(canCreateSQLSnippet: boolean) {
const { data } = contentStore.createOptimistically(snippet)
// update the tabs in the sql editor storage to match the content store
- const tabs = sqlEditorStore.tabsFromContentStore(contentStore, user?.id)
+ const tabs = sqlEditorStore.tabsFromContentStore(contentStore, profile?.id)
sqlEditorStore.loadTabs(tabs, false)
// select tab with new snippet
@@ -46,6 +46,6 @@ export function useOptimisticSqlSnippetCreate(canCreateSQLSnippet: boolean) {
})
}
},
- [user, sqlEditorStore, contentStore]
+ [profile, sqlEditorStore, contentStore]
)
}
diff --git a/studio/pages/project/[ref]/reports/index.tsx b/studio/pages/project/[ref]/reports/index.tsx
index c1a46a2a340..aece220eb06 100644
--- a/studio/pages/project/[ref]/reports/index.tsx
+++ b/studio/pages/project/[ref]/reports/index.tsx
@@ -5,10 +5,10 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { NextPageWithLayout } from 'types'
import { checkPermissions, useFlag, useParams, useStore } from 'hooks'
-import { useUser } from 'lib/auth'
import { post } from 'lib/common/fetch'
import { API_URL, PROJECT_STATUS } from 'lib/constants'
import { useProjectContentStore } from 'stores/projectContentStore'
+import { useProfileQuery } from 'data/profile/profile-query'
import Loading from 'components/ui/Loading'
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
import { createReport } from 'components/to-be-cleaned/Reports/Reports.utils'
@@ -20,14 +20,14 @@ export const UserReportPage: NextPageWithLayout = () => {
const router = useRouter()
const { ref } = useParams()
- const user = useUser()
+ const { data: profile } = useProfileQuery()
const { ui } = useStore()
const project = ui.selectedProject
const contentStore = useProjectContentStore(ref)
const canCreateReport = checkPermissions(PermissionAction.CREATE, 'user_content', {
- resource: { type: 'report', owner_id: user?.id },
- subject: { id: user?.id },
+ resource: { type: 'report', owner_id: profile?.id },
+ subject: { id: profile?.id },
})
const kpsEnabled = useFlag('initWithKps')