Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/webapp/app/routes/api.v1.projects.$projectRef.$env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { env as processEnv } from "~/env.server";
import {
authenticatedEnvironmentForAuthentication,
authenticateRequest,
branchNameFromRequest,
} from "~/services/apiAuth.server";

const ParamsSchema = z.object({
Expand Down Expand Up @@ -32,7 +33,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
projectRef,
env
env,
branchNameFromRequest(request)
);

const result: GetProjectEnvResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { prisma } from "~/db.server";
import {
authenticateRequest,
authenticatedEnvironmentForAuthentication,
branchNameFromRequest,
} from "~/services/apiAuth.server";
import zlib from "node:zlib";

Expand All @@ -29,7 +30,8 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
parsedParams.data.projectRef,
parsedParams.data.envSlug
parsedParams.data.envSlug,
branchNameFromRequest(request)
);

// Find the background worker and tasks and files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { prisma } from "~/db.server";
import {
authenticateRequest,
authenticatedEnvironmentForAuthentication,
branchNameFromRequest,
} from "~/services/apiAuth.server";
import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server";

Expand All @@ -30,7 +31,8 @@ export async function action({ params, request }: ActionFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
parsedParams.data.projectRef,
parsedParams.data.slug
parsedParams.data.slug,
branchNameFromRequest(request)
);

// Find the environment variable
Expand Down Expand Up @@ -106,7 +108,8 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
parsedParams.data.projectRef,
parsedParams.data.slug
parsedParams.data.slug,
branchNameFromRequest(request)
);

// Find the environment variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from "zod";
import {
authenticateRequest,
authenticatedEnvironmentForAuthentication,
branchNameFromRequest,
} from "~/services/apiAuth.server";
import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server";

Expand All @@ -28,7 +29,8 @@ export async function action({ params, request }: ActionFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
parsedParams.data.projectRef,
parsedParams.data.slug
parsedParams.data.slug,
branchNameFromRequest(request)
);

const jsonBody = await request.json();
Expand Down Expand Up @@ -75,7 +77,8 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const environment = await authenticatedEnvironmentForAuthentication(
authenticationResult,
parsedParams.data.projectRef,
parsedParams.data.slug
parsedParams.data.slug,
branchNameFromRequest(request)
);

const repository = new EnvironmentVariablesRepository();
Expand Down
16 changes: 10 additions & 6 deletions apps/webapp/app/services/apiAuth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ export async function authenticatedEnvironmentForAuthentication(
throw json({ error: "Project not found" }, { status: 404 });
}

if (!branch) {
const sanitizedBranch = sanitizeBranchName(branch);

if (!sanitizedBranch) {
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
Expand Down Expand Up @@ -526,8 +528,8 @@ export async function authenticatedEnvironmentForAuthentication(
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
slug: slug,
branchName: sanitizeBranchName(branch),
type: "PREVIEW",
branchName: sanitizedBranch,
archivedAt: null,
},
include: {
Expand Down Expand Up @@ -574,7 +576,9 @@ export async function authenticatedEnvironmentForAuthentication(
throw json({ error: "Project not found" }, { status: 404 });
}

if (!branch) {
const sanitizedBranch = sanitizeBranchName(branch);

if (!sanitizedBranch) {
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
Expand All @@ -596,8 +600,8 @@ export async function authenticatedEnvironmentForAuthentication(
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
slug: slug,
branchName: sanitizeBranchName(branch),
type: "PREVIEW",
branchName: sanitizedBranch,
archivedAt: null,
},
include: {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/v3/gitBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function isValidGitBranchName(branch: string): boolean {
return true;
}

export function sanitizeBranchName(ref: string): string | null {
export function sanitizeBranchName(ref: string | undefined): string | null {
if (!ref) return null;
if (ref.startsWith("refs/heads/")) return ref.substring("refs/heads/".length);
if (ref.startsWith("refs/remotes/")) return ref.substring("refs/remotes/".length);
Expand Down
Loading