Skip to content

Commit

Permalink
adds system app config for FE env vars (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei authored Nov 28, 2023
1 parent f3ff2c7 commit 5d5508c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
15 changes: 15 additions & 0 deletions frontend/app/api/config/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isAuthEnabled } from '@/api-only/auth-config';
import { withNeosyncContext } from '@/api-only/neosync-context';
import { SystemAppConfig } from '@/app/config/app-config';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest): Promise<NextResponse> {
return withNeosyncContext(async () => {
const sysConfig: SystemAppConfig = {
isAuthEnabled: isAuthEnabled(),
publicAppBaseUrl:
process.env.NEXT_PUBLIC_APP_BASE_URL ?? 'http://localhost:3000',
};
return sysConfig;
})(req);
}
4 changes: 4 additions & 0 deletions frontend/app/config/app-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SystemAppConfig {
isAuthEnabled: boolean;
publicAppBaseUrl: string;
}
7 changes: 4 additions & 3 deletions frontend/app/settings/components/InviteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
} from '@/components/ui/table';
import { useToast } from '@/components/ui/use-toast';
import { useGetAccountInvites } from '@/libs/hooks/useGetAccountInvites';
import { useGetInviteLink } from '@/libs/hooks/useGetInviteLink';
import { useGetSystemAppConfig } from '@/libs/hooks/useGetSystemAppConfig';
import { AccountInvite } from '@/neosync-api-client/mgmt/v1alpha1/user_account_pb';
import { formatDateTime, getErrorMessage } from '@/util/util';
import { PlainMessage, Timestamp } from '@bufbuild/protobuf';
import { TrashIcon } from '@radix-ui/react-icons';
import InviteUserForm from './InviteUserForm';
import InviteUserForm, { buildInviteLink } from './InviteUserForm';

interface ColumnProps {
onDeleted(id: string): void;
Expand Down Expand Up @@ -269,7 +269,8 @@ interface CopyInviteButtonProps {
}

function CopyInviteButton({ token }: CopyInviteButtonProps) {
const link = useGetInviteLink(token);
const { data: systemAppData } = useGetSystemAppConfig();
const link = buildInviteLink(systemAppData?.publicAppBaseUrl ?? '', token);

return (
<CopyButton
Expand Down
9 changes: 7 additions & 2 deletions frontend/app/settings/components/InviteUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { toast } from '@/components/ui/use-toast';
import { useGetInviteLink } from '@/libs/hooks/useGetInviteLink';
import { useGetSystemAppConfig } from '@/libs/hooks/useGetSystemAppConfig';
import {
InviteUserToTeamAccountRequest,
InviteUserToTeamAccountResponse,
Expand Down Expand Up @@ -151,7 +151,8 @@ interface InviteCreatedDialogProps {

function InviteCreatedDialog(props: InviteCreatedDialogProps): ReactElement {
const { open, setOpen, token } = props;
const link = useGetInviteLink(token);
const { data: systemAppData } = useGetSystemAppConfig();
const link = buildInviteLink(systemAppData?.publicAppBaseUrl ?? '', token);

return (
<Dialog open={open} onOpenChange={setOpen}>
Expand Down Expand Up @@ -207,3 +208,7 @@ async function inviteUserToTeamAccount(
}
return InviteUserToTeamAccountResponse.fromJson(await res.json());
}

export function buildInviteLink(baseUrl: string, token: string): string {
return `${baseUrl}/invite?token=${token}`;
}
3 changes: 0 additions & 3 deletions frontend/libs/hooks/useGetInviteLink.ts

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/libs/hooks/useGetSystemAppConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { SystemAppConfig } from '@/app/config/app-config';
import type { HookReply } from './types';
import { useNucleusAuthenticatedFetch } from './useNucleusAuthenticatedFetch';

export function useGetSystemAppConfig(): HookReply<SystemAppConfig> {
return useNucleusAuthenticatedFetch<SystemAppConfig>(`/api/config`);
}

0 comments on commit 5d5508c

Please sign in to comment.