Skip to content

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

Fix not org owner error when creating project after creating a new org

Joshen Limd6deeb3916be
diff --git a/studio/pages/new/index.tsx b/studio/pages/new/index.tsx
index e095e1b1648..8d2cf5477e1 100644
--- a/studio/pages/new/index.tsx
+++ b/studio/pages/new/index.tsx
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { observer } from 'mobx-react-lite'
import { Button, Typography } from '@supabase/ui'
-import Router from 'next/router'
+import { useRouter } from 'next/router'
import { API_URL } from 'lib/constants'
import { useStore, withAuth } from 'hooks'
@@ -15,6 +15,8 @@ import Panel from 'components/to-be-cleaned/Panel'
*/
const Wizard = () => {
const { ui, app } = useStore()
+ const router = useRouter()
+
const [orgName, setOrgName] = useState('')
const [newOrgLoading, setNewOrgLoading] = useState(false)
@@ -49,11 +51,7 @@ const Wizard = () => {
} else {
const org = response
app.onOrgAdded(org)
-
- // Router.push('/new/[slug]', `/new/${org.slug}`)
- // Using window.location.href for now as organization metadata needs to refresh
- // We do not get is_owner nor stripe_customer_id from the response here
- window.location.href = `/new/${org.slug}`
+ router.push(`/new/${org.slug}`)
}
}
@@ -70,7 +68,7 @@ const Wizard = () => {
]}
footer={[
<div key="panel-footer" className="flex items-center w-full justify-between">
- <Button type="default" onClick={() => Router.push('/')}>
+ <Button type="default" onClick={() => router.push('/')}>
Cancel
</Button>
<div className="space-x-3">
diff --git a/studio/stores/app/AppStore.ts b/studio/stores/app/AppStore.ts
index b50a0bebfd0..4ce562ef5b8 100644
--- a/studio/stores/app/AppStore.ts
+++ b/studio/stores/app/AppStore.ts
@@ -1,6 +1,6 @@
import { cloneDeep } from 'lodash'
import { values } from 'mobx'
-import { Project } from 'types'
+import { Organization, Project } from 'types'
import { API_URL, STRIPE_PRODUCT_IDS } from 'lib/constants'
import { IRootStore } from '../RootStore'
@@ -71,19 +71,23 @@ export default class AppStore implements IAppStore {
}
}
- onOrgUpdated(org: any) {
- if (org && org.id) {
- this.organizations.data[org.id] = { ...org }
+ onOrgUpdated(updatedOrg: Organization) {
+ if (updatedOrg && updatedOrg.id) {
+ const originalOrg = this.organizations.data[updatedOrg.id]
+ this.organizations.data[updatedOrg.id] = {
+ ...originalOrg,
+ ...updatedOrg,
+ }
}
}
- onOrgAdded(org: any) {
+ onOrgAdded(org: Organization) {
if (org && org.id) {
- this.organizations.data[org.id] = { ...org }
+ this.organizations.data[org.id] = org
}
}
- onOrgDeleted(org: any) {
+ onOrgDeleted(org: Organization) {
if (org && org.id) {
const projects = values(this.projects.data)
// cleanup projects saved queries
diff --git a/studio/types/base.ts b/studio/types/base.ts
index 08799a0c9c0..f4ebb0b542f 100644
--- a/studio/types/base.ts
+++ b/studio/types/base.ts
@@ -4,9 +4,13 @@ export interface Organization {
name: string
billing_email: string
project_limit: number
+ members: any[]
+ projects: any[]
+ is_owner?: boolean
stripe_customer_id?: string
+ stripe_customer_object?: any
total_free_projects?: number
- is_owner?: boolean
+ total_paid_projects?: number
}
export interface Project {