feat(dashboard): introduce service based env vars
fix `@nhost/nextjs` and `@nhost/react` constructors
This commit is contained in:
5
.changeset/friendly-knives-admire.md
Normal file
5
.changeset/friendly-knives-admire.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@nhost/react': patch
|
||||
---
|
||||
|
||||
fix(react): accept service URLs
|
||||
5
.changeset/honest-bats-invite.md
Normal file
5
.changeset/honest-bats-invite.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@nhost/nextjs': patch
|
||||
---
|
||||
|
||||
fix(nextjs): accept service URLs
|
||||
@@ -20,7 +20,9 @@ import {
|
||||
import { loadStripe } from '@stripe/stripe-js';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK!);
|
||||
const stripePromise = process.env.NEXT_PUBLIC_STRIPE_PK
|
||||
? loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK)
|
||||
: null;
|
||||
|
||||
type AddPaymentMethodFormProps = {
|
||||
close: () => void;
|
||||
|
||||
@@ -12,6 +12,7 @@ import useBuckets from '@/hooks/useBuckets';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import useFiles from '@/hooks/useFiles';
|
||||
import useFilesAggregate from '@/hooks/useFilesAggregate';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import { showLoadingToast, triggerToast } from '@/utils/toast';
|
||||
import type { Files } from '@/utils/__generated__/graphql';
|
||||
import { Order_By as OrderBy } from '@/utils/__generated__/graphql';
|
||||
@@ -261,7 +262,7 @@ export default function FilesDataGrid(props: FilesDataGridProps) {
|
||||
const { fileMetadata, error: fileError } = await appClient.storage
|
||||
.setAdminSecret(
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication.hasuraGraphqlAdminSecret,
|
||||
)
|
||||
.upload({
|
||||
|
||||
@@ -8,6 +8,7 @@ import Chip from '@/ui/Chip';
|
||||
import type { FileUploadButtonProps } from '@/ui/FileUploadButton';
|
||||
import FileUploadButton from '@/ui/FileUploadButton';
|
||||
import Button from '@/ui/v2/Button';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import { triggerToast } from '@/utils/toast';
|
||||
import type { Files } from '@/utils/__generated__/graphql';
|
||||
import type { DetailedHTMLProps, HTMLProps } from 'react';
|
||||
@@ -73,7 +74,7 @@ export default function FilesDataGridControls({
|
||||
try {
|
||||
const storageWithAdminSecret = appClient.storage.setAdminSecret(
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication.hasuraGraphqlAdminSecret,
|
||||
);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@/types/dataBrowser';
|
||||
import { getPreparedHasuraQuery } from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
import prepareCreateColumnQuery from './prepareCreateColumnQuery';
|
||||
|
||||
export interface CreateColumnMigrationVariables {
|
||||
@@ -34,30 +34,27 @@ export default async function createColumnMigration({
|
||||
column,
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_add_column_${column.name}`,
|
||||
down: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'ALTER TABLE %I.%I DROP COLUMN IF EXISTS %I',
|
||||
schema,
|
||||
table,
|
||||
column.name,
|
||||
),
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_add_column_${column.name}`,
|
||||
down: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'ALTER TABLE %I.%I DROP COLUMN IF EXISTS %I',
|
||||
schema,
|
||||
table,
|
||||
column.name,
|
||||
),
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -52,7 +53,7 @@ export default function useCreateColumnMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useCreateRecordMutation<TData extends object = {}>({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@/types/dataBrowser';
|
||||
import { getPreparedHasuraQuery } from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
import prepareCreateTableQuery from './prepareCreateTableQuery';
|
||||
|
||||
export interface CreateTableMigrationVariables {
|
||||
@@ -28,29 +28,26 @@ export default async function createTableMigration({
|
||||
}: CreateTableMigrationOptions & CreateTableMigrationVariables) {
|
||||
const args = prepareCreateTableQuery({ dataSource, schema, table });
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `create_table_${schema}_${table.name}`,
|
||||
down: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'DROP TABLE IF EXISTS %I.%I',
|
||||
schema,
|
||||
table.name,
|
||||
),
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `create_table_${schema}_${table.name}`,
|
||||
down: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'DROP TABLE IF EXISTS %I.%I',
|
||||
schema,
|
||||
table.name,
|
||||
),
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -50,7 +51,7 @@ export default function useCreateTableMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -51,7 +52,7 @@ export default function useDatabaseQuery(
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
}),
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
} from '@/types/dataBrowser';
|
||||
import { getPreparedHasuraQuery } from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
|
||||
export interface DeleteColumnMigrationVariables {
|
||||
/**
|
||||
@@ -46,30 +46,27 @@ export default async function deleteColumnMigration({
|
||||
},
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_drop_column_${column.id}`,
|
||||
down: recreateColumnArgs,
|
||||
up: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'ALTER TABLE %I.%I DROP COLUMN IF EXISTS %I CASCADE',
|
||||
schema,
|
||||
table,
|
||||
column.id,
|
||||
),
|
||||
],
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_drop_column_${column.id}`,
|
||||
down: recreateColumnArgs,
|
||||
up: [
|
||||
getPreparedHasuraQuery(
|
||||
dataSource,
|
||||
'ALTER TABLE %I.%I DROP COLUMN IF EXISTS %I CASCADE',
|
||||
schema,
|
||||
table,
|
||||
column.id,
|
||||
),
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useDeleteColumnMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -49,7 +50,7 @@ export default function useDeleteRecordMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
getPreparedHasuraQuery,
|
||||
} from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
|
||||
export interface DeleteTableMigrationVariables {
|
||||
/**
|
||||
@@ -40,32 +40,29 @@ export default async function deleteTable({
|
||||
),
|
||||
];
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `drop_table_${schema}_${table}`,
|
||||
down: [
|
||||
{
|
||||
type: 'run_sql',
|
||||
args: {
|
||||
cascade: false,
|
||||
read_only: false,
|
||||
source: '',
|
||||
sql: getEmptyDownMigrationMessage(deleteTableArgs),
|
||||
},
|
||||
},
|
||||
],
|
||||
up: deleteTableArgs,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `drop_table_${schema}_${table}`,
|
||||
down: [
|
||||
{
|
||||
type: 'run_sql',
|
||||
args: {
|
||||
cascade: false,
|
||||
read_only: false,
|
||||
source: '',
|
||||
sql: getEmptyDownMigrationMessage(deleteTableArgs),
|
||||
},
|
||||
},
|
||||
],
|
||||
up: deleteTableArgs,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -48,7 +49,7 @@ export default function useDeleteTableMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
}),
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
QueryResult,
|
||||
} from '@/types/dataBrowser';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
|
||||
export interface ManagePermissionMigrationVariables {
|
||||
/**
|
||||
@@ -109,22 +109,19 @@ export default async function managePermissionMigration({
|
||||
};
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `change_${action}_permission_${role}_${schema}_${table}`,
|
||||
down: args.down,
|
||||
up: args.up,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `change_${action}_permission_${role}_${schema}_${table}`,
|
||||
down: args.down,
|
||||
up: args.up,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -56,7 +57,7 @@ export default function useManagePermissionMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useMetadataQuery(
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useTableQuery(
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
QueryResult,
|
||||
} from '@/types/dataBrowser';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
import prepareTrackForeignKeyRelationsMetadata from './prepareTrackForeignKeyRelationsMetadata';
|
||||
|
||||
export interface TrackForeignKeyRelationsMigrationVariables {
|
||||
@@ -46,23 +46,20 @@ export default async function trackForeignKeyRelationsMigration({
|
||||
foreignKeyRelations,
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `track_foreign_key_relations_${schema}_${table}`,
|
||||
down: [],
|
||||
up: creatableRelationships,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `track_foreign_key_relations_${schema}_${table}`,
|
||||
down: [],
|
||||
up: creatableRelationships,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -50,7 +51,7 @@ export default function useTrackForeignKeyRelationMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
}),
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
QueryResult,
|
||||
} from '@/types/dataBrowser';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
|
||||
export interface TrackTableMigrationVariables {
|
||||
/**
|
||||
@@ -24,32 +24,29 @@ export default async function trackTableMigration({
|
||||
adminSecret,
|
||||
table,
|
||||
}: TrackTableMigrationOptions & TrackTableMigrationVariables) {
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `add_existing_table_or_view_${schema}_${table.name}`,
|
||||
down: [
|
||||
{
|
||||
type: 'pg_untrack_table',
|
||||
args: { source: dataSource, table: { schema, name: table.name } },
|
||||
},
|
||||
],
|
||||
up: [
|
||||
{
|
||||
args: { source: dataSource, table: { schema, name: table.name } },
|
||||
type: 'pg_track_table',
|
||||
},
|
||||
],
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `add_existing_table_or_view_${schema}_${table.name}`,
|
||||
down: [
|
||||
{
|
||||
type: 'pg_untrack_table',
|
||||
args: { source: dataSource, table: { schema, name: table.name } },
|
||||
},
|
||||
],
|
||||
up: [
|
||||
{
|
||||
args: { source: dataSource, table: { schema, name: table.name } },
|
||||
type: 'pg_track_table',
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -48,7 +49,7 @@ export default function useTrackTableMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@/types/dataBrowser';
|
||||
import { getEmptyDownMigrationMessage } from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
import prepareUpdateColumnQuery from './prepareUpdateColumnQuery';
|
||||
|
||||
export interface UpdateColumnMigrationVariables {
|
||||
@@ -66,22 +66,19 @@ export default async function updateColumnMigration({
|
||||
];
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_alter_column_${originalColumn.name}`,
|
||||
down: columnUpdateDownMigration,
|
||||
up: columnUpdateUpMigration,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${table}_alter_column_${originalColumn.name}`,
|
||||
down: columnUpdateDownMigration,
|
||||
up: columnUpdateUpMigration,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useUpdateColumnMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -53,7 +54,7 @@ export default function useUpdateRecordMutation<TData extends object = {}>({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
} from '@/types/dataBrowser';
|
||||
import { getEmptyDownMigrationMessage } from '@/utils/dataBrowser/hasuraQueryHelpers';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { getLocalHasuraMigrationServiceUrl } from '@/utils/env';
|
||||
import { getHasuraMigrationsApiUrl } from '@/utils/env';
|
||||
import prepareUpdateTableQuery from './prepareUpdateTableQuery';
|
||||
|
||||
export interface UpdateTableMigrationVariables {
|
||||
@@ -57,32 +57,29 @@ export default async function updateTableMigration({
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${getLocalHasuraMigrationServiceUrl()}/apis/migrate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${originalTable.table_name}`,
|
||||
down: [
|
||||
{
|
||||
type: 'run_sql',
|
||||
args: {
|
||||
cascade: false,
|
||||
read_only: false,
|
||||
source: '',
|
||||
sql: getEmptyDownMigrationMessage(args),
|
||||
},
|
||||
},
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
const response = await fetch(`${getHasuraMigrationsApiUrl()}/apis/migrate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-hasura-admin-secret': adminSecret,
|
||||
},
|
||||
);
|
||||
body: JSON.stringify({
|
||||
dataSource,
|
||||
skip_execution: false,
|
||||
name: `alter_table_${schema}_${originalTable.table_name}`,
|
||||
down: [
|
||||
{
|
||||
type: 'run_sql',
|
||||
args: {
|
||||
cascade: false,
|
||||
read_only: false,
|
||||
source: '',
|
||||
sql: getEmptyDownMigrationMessage(args),
|
||||
},
|
||||
},
|
||||
],
|
||||
up: args,
|
||||
}),
|
||||
});
|
||||
|
||||
const responseData: [AffectedRowsResult, QueryResult<string[]>] | QueryError =
|
||||
await response.json();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { MutationOptions } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -49,7 +50,7 @@ export default function useUpdateTableMutation({
|
||||
appUrl: customAppUrl || appUrl,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: customAdminSecret || currentApplication?.hasuraGraphqlAdminSecret,
|
||||
dataSource: customDataSource || (dataSourceSlug as string),
|
||||
schema: customSchema || (schemaSlug as string),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { QueryError, QueryResult } from '@/types/dataBrowser';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import normalizeQueryError from '@/utils/dataBrowser/normalizeQueryError';
|
||||
import { isPlatform } from '@/utils/env';
|
||||
|
||||
export interface FetchProjectDatabaseSizeOptions {
|
||||
/**
|
||||
@@ -32,6 +33,7 @@ export default async function fetchProjectDatabaseSize({
|
||||
region,
|
||||
adminSecret,
|
||||
}: FetchProjectDatabaseSizeOptions): Promise<FetchProjectDatabaseSizeReturnType> {
|
||||
const IS_PLATFORM = isPlatform();
|
||||
const response = await fetch(
|
||||
`${generateAppServiceUrl(subdomain, region, 'hasura')}/v2/query`,
|
||||
{
|
||||
@@ -43,7 +45,7 @@ export default async function fetchProjectDatabaseSize({
|
||||
type: 'run_sql',
|
||||
args: {
|
||||
sql: `SELECT pg_database_size('${
|
||||
subdomain && !region ? 'postgres' : subdomain
|
||||
!IS_PLATFORM ? 'postgres' : subdomain
|
||||
}');`,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { FetchProjectDatabaseSizeReturnType } from './fetchProjectDatabaseSize';
|
||||
@@ -25,7 +26,7 @@ export default function useDatabaseSizeOfApplication(
|
||||
region: currentApplication?.region?.awsName,
|
||||
adminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication?.hasuraGraphqlAdminSecret,
|
||||
}),
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useUserDataContext } from '@/context/workspace1-context';
|
||||
import type { Application } from '@/types/application';
|
||||
import { ApplicationStatus } from '@/types/application';
|
||||
import type { Workspace } from '@/types/workspace';
|
||||
import { getSubdomain } from '@/utils/env';
|
||||
import { getHasuraAdminSecret, getSubdomain } from '@/utils/env';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect, useState } from 'react';
|
||||
import useIsPlatform from './common/useIsPlatform';
|
||||
@@ -32,7 +32,7 @@ export function useCurrentWorkspaceAndApplication(): UseCurrentWorkspaceAndAppli
|
||||
id: 'local',
|
||||
slug: 'local',
|
||||
name: 'local',
|
||||
hasuraGraphqlAdminSecret: 'nhost-admin-secret',
|
||||
hasuraGraphqlAdminSecret: getHasuraAdminSecret(),
|
||||
appStates: [
|
||||
{
|
||||
id: 'local',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import type {
|
||||
Files_Order_By as FilesOrderBy,
|
||||
GetFilesQuery,
|
||||
@@ -92,7 +93,7 @@ export default function useFiles({
|
||||
headers: {
|
||||
'x-hasura-admin-secret':
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication?.hasuraGraphqlAdminSecret,
|
||||
},
|
||||
mode: 'cors',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
@@ -26,7 +27,7 @@ export function useRemoteApplicationGQLClient() {
|
||||
headers: {
|
||||
'x-hasura-admin-secret':
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication?.hasuraGraphqlAdminSecret,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useWorkspaceContext } from '@/context/workspace-context';
|
||||
import { useUserDataContext } from '@/context/workspace1-context';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect } from 'react';
|
||||
import { useCurrentWorkspaceAndApplication } from './useCurrentWorkspaceAndApplication';
|
||||
@@ -39,7 +40,7 @@ export const useSetAppWorkspaceContextFromUserContext = () => {
|
||||
appIsProvisioned: currentApplication.isProvisioned,
|
||||
appAdminSecret:
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication.hasuraGraphqlAdminSecret,
|
||||
repository: currentApplication.githubRepository,
|
||||
provisioning:
|
||||
|
||||
@@ -4,6 +4,7 @@ import FilesDataGrid from '@/components/files/FilesDataGrid';
|
||||
import ProjectLayout from '@/components/layout/ProjectLayout';
|
||||
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
|
||||
import { getHasuraAdminSecret } from '@/utils/env';
|
||||
import { NhostApolloProvider } from '@nhost/react-apollo';
|
||||
import type { ReactElement } from 'react';
|
||||
|
||||
@@ -25,7 +26,7 @@ export default function StoragePage() {
|
||||
headers={{
|
||||
'x-hasura-admin-secret':
|
||||
process.env.NEXT_PUBLIC_ENV === 'dev'
|
||||
? 'nhost-admin-secret'
|
||||
? getHasuraAdminSecret()
|
||||
: currentApplication.hasuraGraphqlAdminSecret,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { getLocalHasuraServiceUrl, getLocalServicesPort } from '@/utils/env';
|
||||
import {
|
||||
getAuthServiceUrl,
|
||||
getFunctionsServiceUrl,
|
||||
getGraphqlServiceUrl,
|
||||
getHasuraSchemaApiUrl,
|
||||
getLocalHasuraServiceUrl,
|
||||
getStorageServiceUrl,
|
||||
isPlatform,
|
||||
} from '@/utils/env';
|
||||
|
||||
export type NhostService =
|
||||
| 'auth'
|
||||
@@ -50,35 +58,42 @@ export default function generateAppServiceUrl(
|
||||
localBackendSlugs = defaultLocalBackendSlugs,
|
||||
remoteBackendSlugs = defaultRemoteBackendSlugs,
|
||||
) {
|
||||
const LOCAL_SERVICES_PORT = getLocalServicesPort();
|
||||
// // We are treating this case as if NEXT_PUBLIC_NHOST_PLATFORM is true,
|
||||
// // but we need to make sure to use Hasura URLs are pointing to `localhost`
|
||||
// // as this is currently a limitation of Hasura.
|
||||
// if (subdomain && subdomain !== 'localhost' && !region) {
|
||||
// if (service === 'hasura') {
|
||||
// return `${LOCAL_HASURA_URL}${localBackendSlugs[service]}`;
|
||||
// }
|
||||
|
||||
// const nhostBackend =
|
||||
// process.env.NEXT_PUBLIC_ENV === 'staging'
|
||||
// ? 'staging.nhost.run'
|
||||
// : 'nhost.run';
|
||||
|
||||
// const customSubdomainWithProtocol = `https://${subdomain}`;
|
||||
|
||||
// if (LOCAL_SERVICES_PORT && LOCAL_SERVICES_PORT !== '443') {
|
||||
// return `${customSubdomainWithProtocol}.${nhostBackend}:${LOCAL_SERVICES_PORT}${localBackendSlugs[service]}`;
|
||||
// }
|
||||
|
||||
// return `${customSubdomainWithProtocol}.${nhostBackend}${localBackendSlugs[service]}`;
|
||||
// }
|
||||
const IS_PLATFORM = isPlatform();
|
||||
const serviceUrls: Record<typeof service, string> = {
|
||||
auth: getAuthServiceUrl(),
|
||||
graphql: getGraphqlServiceUrl(),
|
||||
storage: getStorageServiceUrl(),
|
||||
functions: getFunctionsServiceUrl(),
|
||||
hasura: getHasuraSchemaApiUrl(),
|
||||
};
|
||||
|
||||
if (!IS_PLATFORM && serviceUrls[service]) {
|
||||
return serviceUrls[service];
|
||||
}
|
||||
|
||||
const LOCAL_HASURA_URL = getLocalHasuraServiceUrl();
|
||||
|
||||
// We are treating this case as if NEXT_PUBLIC_NHOST_PLATFORM is true,
|
||||
// but we need to make sure to use Hasura URLs are pointing to `localhost`
|
||||
// as this is currently a limitation of Hasura.
|
||||
if (subdomain && subdomain !== 'localhost' && !region) {
|
||||
if (service === 'hasura') {
|
||||
return `${LOCAL_HASURA_URL}${localBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
const nhostBackend =
|
||||
process.env.NEXT_PUBLIC_ENV === 'staging'
|
||||
? 'staging.nhost.run'
|
||||
: 'nhost.run';
|
||||
|
||||
const customSubdomainWithProtocol = `https://${subdomain}`;
|
||||
|
||||
if (LOCAL_SERVICES_PORT && LOCAL_SERVICES_PORT !== '443') {
|
||||
return `${customSubdomainWithProtocol}.${nhostBackend}:${LOCAL_SERVICES_PORT}${localBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
return `${customSubdomainWithProtocol}.${nhostBackend}${localBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
if (process.env.NEXT_PUBLIC_NHOST_PLATFORM !== 'true') {
|
||||
return `${LOCAL_HASURA_URL}${localBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
if (process.env.NEXT_PUBLIC_ENV === 'dev') {
|
||||
return `${process.env.NEXT_PUBLIC_NHOST_BACKEND_URL || LOCAL_HASURA_URL}${
|
||||
localBackendSlugs[service]
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* Determines whether the Nhost Dashboard is running in a cloud environment.
|
||||
*/
|
||||
export function isPlatform() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_PLATFORM === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Port of the locally running services exposed by the CLI.
|
||||
*/
|
||||
@@ -17,13 +24,6 @@ export function getLocalHasuraPort() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Port of the migration service exposed by Hasura.
|
||||
*/
|
||||
export function getLocalHasuraMigrationsPort() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_LOCAL_MIGRATIONS_PORT || '9693';
|
||||
}
|
||||
|
||||
/**
|
||||
* Port of Hasura Console.
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ export function getLocalHasuraConsolePort() {
|
||||
* Subdomain of the Nhost project.
|
||||
*/
|
||||
export function getSubdomain() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_LOCAL_SUBDOMAIN || 'localdev';
|
||||
return process.env.NEXT_PUBLIC_NHOST_LOCAL_SUBDOMAIN;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,14 +72,6 @@ export function getLocalHasuraServiceUrl() {
|
||||
return `http://localhost:${getLocalHasuraPort()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of Hasura's Migrations API. This is only used when running the Nhost
|
||||
* Dashboard locally.
|
||||
*/
|
||||
export function getLocalHasuraMigrationServiceUrl() {
|
||||
return `http://localhost:${getLocalHasuraMigrationsPort()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend URL for the locally running instance. This is only used when running
|
||||
* the Nhost Dashboard locally.
|
||||
@@ -93,3 +85,83 @@ export function getLocalBackendUrl() {
|
||||
|
||||
return `https://${getLocalSubdomain()}.nhost.run:${getLocalServicesPort()}`;
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
|
||||
/**
|
||||
* Admin secret for Hasura.
|
||||
*/
|
||||
export function getHasuraAdminSecret() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_ADMIN_SECRET || 'nhost-admin-secret';
|
||||
}
|
||||
|
||||
/**
|
||||
* Suffix for the migration service exposed by Hasura.
|
||||
*/
|
||||
export function getMigrationsApiSuffix() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_MIGRATIONS_API_SUFFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Port of the migration service exposed by Hasura.
|
||||
*/
|
||||
export function getMigrationsApiPort() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_MIGRATIONS_API_PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the Auth service.
|
||||
*/
|
||||
export function getAuthServiceUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_AUTH_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the GraphQL service.
|
||||
*/
|
||||
export function getGraphqlServiceUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_GRAPHQL_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the Storage service.
|
||||
*/
|
||||
export function getStorageServiceUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_STORAGE_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the Functions service.
|
||||
*/
|
||||
export function getFunctionsServiceUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_FUNCTIONS_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the Hasura service.
|
||||
*/
|
||||
export function getHasuraConsoleServiceUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_HASURA_CONSOLE_URL;
|
||||
}
|
||||
|
||||
export function getHasuraMigrationsApiUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_HASURA_MIGRATIONS_API_URL;
|
||||
}
|
||||
|
||||
export function getHasuraSchemaApiUrl() {
|
||||
return process.env.NEXT_PUBLIC_NHOST_HASURA_SCHEMA_API_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom URL of the Hasura Migrations API.
|
||||
*/
|
||||
// export function getMigrationServiceUrl() {
|
||||
// const serviceUrl = getHasuraServiceUrl();
|
||||
// const port = getMigrationsApiPort();
|
||||
// const suffix = getMigrationsApiSuffix();
|
||||
|
||||
// if (port) {
|
||||
// return `${serviceUrl}:${port}${suffix}`;
|
||||
// }
|
||||
// return `${serviceUrl}${suffix}`;
|
||||
// }
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
import { getLocalSubdomain } from '@/utils/env';
|
||||
import {
|
||||
getAuthServiceUrl,
|
||||
getFunctionsServiceUrl,
|
||||
getGraphqlServiceUrl,
|
||||
getStorageServiceUrl,
|
||||
isPlatform,
|
||||
} from '@/utils/env';
|
||||
import { NhostClient } from '@nhost/nextjs';
|
||||
|
||||
export const nhost =
|
||||
process.env.NEXT_PUBLIC_NHOST_PLATFORM === 'true'
|
||||
? new NhostClient({ backendUrl: process.env.NEXT_PUBLIC_NHOST_BACKEND_URL })
|
||||
: new NhostClient({ subdomain: getLocalSubdomain() });
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
export const nhost = isPlatform()
|
||||
? new NhostClient({ backendUrl: process.env.NEXT_PUBLIC_NHOST_BACKEND_URL })
|
||||
: getAuthServiceUrl() &&
|
||||
getGraphqlServiceUrl() &&
|
||||
getStorageServiceUrl() &&
|
||||
getFunctionsServiceUrl()
|
||||
? new NhostClient({
|
||||
authUrl: getAuthServiceUrl(),
|
||||
graphqlUrl: getGraphqlServiceUrl(),
|
||||
storageUrl: getStorageServiceUrl(),
|
||||
functionsUrl: getFunctionsServiceUrl(),
|
||||
})
|
||||
: new NhostClient({ subdomain: 'localhost' });
|
||||
|
||||
export default nhost;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {
|
||||
BackendUrl,
|
||||
NhostAuthConstructorParams,
|
||||
NhostClient as ReactNhostClient,
|
||||
NhostProvider,
|
||||
Subdomain
|
||||
NhostReactClientConstructorParams
|
||||
} from '@nhost/react'
|
||||
import { setNhostSessionInCookie } from './utils'
|
||||
|
||||
@@ -18,18 +16,10 @@ export const NhostNextProvider: typeof NhostProvider = NhostProvider
|
||||
const isBrowser = typeof window !== 'undefined'
|
||||
|
||||
export interface NhostNextClientConstructorParams
|
||||
extends Partial<BackendUrl>,
|
||||
Partial<Subdomain>,
|
||||
Omit<
|
||||
NhostAuthConstructorParams,
|
||||
| 'url'
|
||||
| 'start'
|
||||
| 'client'
|
||||
| 'clientStorage'
|
||||
| 'clientStorageType'
|
||||
| 'clientStorageGetter'
|
||||
| 'clientStorageSetter'
|
||||
> {}
|
||||
extends Omit<
|
||||
NhostReactClientConstructorParams,
|
||||
'clientStorage' | 'clientStorageType' | 'clientStorageGetter' | 'clientStorageSetter'
|
||||
> {}
|
||||
|
||||
export class NhostClient extends ReactNhostClient {
|
||||
constructor(params: NhostNextClientConstructorParams) {
|
||||
|
||||
@@ -26,7 +26,13 @@ export function urlFromSubdomain(
|
||||
throw new Error('Either `backendUrl` or `subdomain` must be set.')
|
||||
}
|
||||
|
||||
// check if subdomain is [http[s]://]localhost[:port] or [http[s]://]localdev[:port]
|
||||
if (subdomain === 'localhost') {
|
||||
console.warn(
|
||||
'The `subdomain` is set to "localhost". Support for this will be removed in a future release. Please use "local" instead.'
|
||||
)
|
||||
}
|
||||
|
||||
// check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]
|
||||
const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)
|
||||
if (subdomainLocalhostFound?.groups) {
|
||||
const { protocol, host, port } = subdomainLocalhostFound.groups
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
BackendUrl,
|
||||
NhostAuthConstructorParams,
|
||||
NhostClient as _VanillaNhostClient,
|
||||
NhostClientConstructorParams as VanillaNhostClientConstructorParams,
|
||||
NhostSession,
|
||||
NHOST_REFRESH_TOKEN_KEY,
|
||||
Subdomain
|
||||
@@ -15,9 +16,7 @@ export { NHOST_REFRESH_TOKEN_KEY }
|
||||
export const VanillaNhostClient = _VanillaNhostClient
|
||||
|
||||
export interface NhostReactClientConstructorParams
|
||||
extends Partial<BackendUrl>,
|
||||
Partial<Subdomain>,
|
||||
Omit<NhostAuthConstructorParams, 'url' | 'start' | 'client'> {}
|
||||
extends Omit<VanillaNhostClientConstructorParams, 'start' | 'client'> {}
|
||||
|
||||
export class NhostClient extends VanillaNhostClient {
|
||||
constructor(params: NhostReactClientConstructorParams) {
|
||||
|
||||
Reference in New Issue
Block a user