Skip to content

Commit

Permalink
fix: Env Rendering in client side components (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk authored Aug 30, 2024
1 parent 2811706 commit f3e1205
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const GithubJobAgentConfig: React.FC<{

<CommandItem>
<a
href={`${env.GITHUB_URL}/apps/${env.GITHUB_BOT_NAME}/installations/select_target?target_id=${githubUser.githubUserId}?redirect_uri=${env.BASE_URL}/${workspaceSlug}/job-agents/add`}
href={`${env.NEXT_PUBLIC_GITHUB_URL}/apps/${env.NEXT_PUBLIC_GITHUB_BOT_NAME}/installations/select_target?target_id=${githubUser.githubUserId}?redirect_uri=${env.NEXT_PUBLIC_BASE_URL}/${workspaceSlug}/job-agents/add`}
className="flex items-center gap-2"
>
<TbPlus />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const GithubOrgConfig: React.FC<{

<CommandItem>
<a
href={`${env.GITHUB_URL}/apps/${env.GITHUB_BOT_NAME}/installations/select_target?target_id=${githubUser?.githubUserId}?redirect_uri=${env.BASE_URL}/${workspaceSlug}/job-agents/add`}
href={`${env.NEXT_PUBLIC_GITHUB_URL}/apps/${env.NEXT_PUBLIC_GITHUB_BOT_NAME}/installations/select_target?target_id=${githubUser?.githubUserId}?redirect_uri=${env.NEXT_PUBLIC_BASE_URL}/${workspaceSlug}/job-agents/add`}
className="flex items-center gap-2"
>
<TbPlus />
Expand Down Expand Up @@ -254,7 +254,7 @@ export const GithubOrgConfig: React.FC<{
<DropdownMenuContent>
<DropdownMenuItem>
<a
href={`${env.GITHUB_URL}/organizations/${github_organization.organizationName}/settings/installations/${github_organization.installationId}`}
href={`${env.NEXT_PUBLIC_GITHUB_URL}/organizations/${github_organization.organizationName}/settings/installations/${github_organization.installationId}`}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { GithubConfigFileSync } from "./GithubConfigFile";
import { GithubOrgConfig } from "./GithubOrgConfig";

const githubAuthUrl = (userId?: string, workspaceSlug?: string) =>
`${env.GITHUB_URL}/login/oauth/authorize?response_type=code&client_id=${env.NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID}&redirect_uri=${env.BASE_URL}/api/github/${userId}/${workspaceSlug}&state=sLtHqpxQ6FiUtBWJ&scope=repo%2Cread%3Auser`;
`${env.NEXT_PUBLIC_GITHUB_URL}/login/oauth/authorize?response_type=code&client_id=${env.NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID}&redirect_uri=${env.NEXT_PUBLIC_BASE_URL}/api/github/${userId}/${workspaceSlug}&state=sLtHqpxQ6FiUtBWJ&scope=repo%2Cread%3Auser`;

export default function GitHubIntegrationPage({
params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const InviteLinkSection: React.FC<{
);
}, [mutateAsync, inviteLink, sessionMember?.workspace_member.id, utils]);

const link = `${env.BASE_URL}/join/${inviteLink.data?.token ?? ""}`;
const link = `${env.NEXT_PUBLIC_BASE_URL}/join/${inviteLink.data?.token ?? ""}`;

const handleCopyClick = () =>
navigator.clipboard.writeText(link).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const GET = async (
const { userId, workspaceSlug } = params;

const tokenResponse = await fetch(
`${env.GITHUB_URL}/login/oauth/access_token`,
`${env.NEXT_PUBLIC_GITHUB_URL}/login/oauth/access_token`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -53,6 +53,6 @@ export const GET = async (
});

return NextResponse.redirect(
`${env.BASE_URL}/${workspaceSlug}/settings/workspace/integrations/github`,
`${env.NEXT_PUBLIC_BASE_URL}/${workspaceSlug}/settings/workspace/integrations/github`,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export const GET = async (
"duplicate key value",
);
if (isDuplicateKeyError)
return NextResponse.redirect(`${env.BASE_URL}/${workspaceSlug}`);
return NextResponse.redirect(
`${env.NEXT_PUBLIC_BASE_URL}/${workspaceSlug}`,
);

throw e;
});

return NextResponse.redirect(`${env.BASE_URL}/${workspaceSlug}`);
return NextResponse.redirect(`${env.NEXT_PUBLIC_BASE_URL}/${workspaceSlug}`);
};
20 changes: 10 additions & 10 deletions apps/webservice/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
BASE_URL: z.string().default("http://localhost:3000"),
GITHUB_URL: z.string().url().default("https://github.com"),
GITHUB_BOT_NAME: z.string().min(1).default("kflag"),
NEXT_PUBLIC_BASE_URL: z.string().default("http://localhost:3000"),
NEXT_PUBLIC_GITHUB_URL: z.string().url().default("https://github.com"),
NEXT_PUBLIC_GITHUB_BOT_NAME: z.string().min(1).default("kflag"),
},
/**
* Specify your server-side environment variables schema here.
Expand All @@ -28,24 +28,24 @@ export const env = createEnv({

/**
* Specify your client-side environment variables schema here.
* For them to be exposed to the client, prefix them with `NEXT_PUBLIC_`.
* For them to be exposed to the client, prefix them with NEXT_PUBLIC_.
*/
client: {
NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID: z.string().optional(),
// NEXT_PUBLIC_CLIENTVAR: z.string(),
},

/**
* Destructure all variables from `process.env` to make sure they aren't tree-shaken away.
* Destructure all variables from process.env to make sure they aren't tree-shaken away.
*/
experimental__runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
BASE_URL: process.env.BASE_URL,
GITHUB_URL: process.env.GITHUB_URL,
GITHUB_BOT_NAME: process.env.GITHUB_BOT_NAME,
NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL,
NEXT_PUBLIC_GITHUB_URL: process.env.NEXT_PUBLIC_GITHUB_URL,
NEXT_PUBLIC_GITHUB_BOT_NAME: process.env.NEXT_PUBLIC_GITHUB_BOT_NAME,
NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID:
process.env.NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},

skipValidation:
!!process.env.CI ||
!!process.env.SKIP_ENV_VALIDATION ||
Expand Down

0 comments on commit f3e1205

Please sign in to comment.