Skip to content

Commit c7dcf57

Browse files
committed
JWTs working are with preview branches
1 parent 46498bb commit c7dcf57

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

apps/webapp/app/models/runtimeEnvironment.server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function findEnvironmentByApiKey(
6262
return environment;
6363
}
6464

65+
/** @deprecated We don't use public api keys anymore */
6566
export async function findEnvironmentByPublicApiKey(
6667
apiKey: string,
6768
branchName: string | undefined
@@ -85,7 +86,9 @@ export async function findEnvironmentByPublicApiKey(
8586
return environment;
8687
}
8788

88-
export async function findEnvironmentById(id: string): Promise<AuthenticatedEnvironment | null> {
89+
export async function findEnvironmentById(
90+
id: string
91+
): Promise<(AuthenticatedEnvironment & { parentEnvironment: { apiKey: string } | null }) | null> {
8992
const environment = await prisma.runtimeEnvironment.findFirst({
9093
where: {
9194
id,
@@ -94,6 +97,11 @@ export async function findEnvironmentById(id: string): Promise<AuthenticatedEnvi
9497
project: true,
9598
organization: true,
9699
orgMember: true,
100+
parentEnvironment: {
101+
select: {
102+
apiKey: true,
103+
},
104+
},
97105
},
98106
});
99107

apps/webapp/app/services/realtime/jwtAuth.server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export async function validatePublicJwtKey(token: string): Promise<ValidatePubli
3333
return { ok: false, error: "Invalid Public Access Token, environment not found." };
3434
}
3535

36-
const result = await validateJWT(token, environment.apiKey);
36+
const result = await validateJWT(
37+
token,
38+
environment.parentEnvironment?.apiKey ?? environment.apiKey
39+
);
3740

3841
if (!result.ok) {
3942
switch (result.code) {

0 commit comments

Comments
 (0)