Skip to content

Commit 6d86acf

Browse files
authored
Merge pull request #241 from cipherstash/nextjs-fix-1
feat(nextjs): Remove node api calls which are incompatible with Next.…
2 parents cb353c3 + 1535259 commit 6d86acf

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

.changeset/sparkly-breads-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cipherstash/nextjs": minor
3+
---
4+
5+
Remove node api calls which are incompatible with Next.js middleware.

packages/nextjs/src/cts/index.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
import { NextResponse } from 'next/server'
2-
import { loadWorkSpaceId } from '../../../utils/config'
32
import { logger } from '../../../utils/logger'
43
import {
54
CS_COOKIE_NAME,
65
type CtsToken,
76
type GetCtsTokenResponse,
87
} from '../index'
98

9+
/**
10+
* Extracts the workspace ID from a CRN string.
11+
* CRN format: crn:region.aws:ID
12+
*
13+
* @param crn The CRN string to extract from
14+
* @returns The workspace ID portion of the CRN
15+
*/
16+
function extractWorkspaceIdFromCrn(crn: string): string {
17+
const match = crn.match(/crn:[^:]+:([^:]+)$/)
18+
if (!match) {
19+
throw new Error('Invalid CRN format')
20+
}
21+
return match[1]
22+
}
23+
24+
export function loadWorkSpaceId(suppliedCrn?: string): string {
25+
if (suppliedCrn) {
26+
return extractWorkspaceIdFromCrn(suppliedCrn)
27+
}
28+
29+
if (!process.env.CS_WORKSPACE_CRN) {
30+
throw new Error(
31+
'You have not defined a workspace CRN in your config file, or the CS_WORKSPACE_CRN environment variable.',
32+
)
33+
}
34+
35+
return extractWorkspaceIdFromCrn(process.env.CS_WORKSPACE_CRN)
36+
}
37+
1038
// Can be used independently of the Next.js middleware
1139
export const fetchCtsToken = async (oidcToken: string): GetCtsTokenResponse => {
1240
const workspaceId = loadWorkSpaceId()

packages/protect/__tests__/lock-context.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'dotenv/config'
22
import { csColumn, csTable } from '@cipherstash/schema'
33
import { beforeAll, describe, expect, it } from 'vitest'
4-
import { LockContext, protect } from '../src'
4+
import { protect } from '../src'
5+
import { LockContext } from '../src/identify'
56

67
const users = csTable('users', {
78
email: csColumn('email').freeTextSearch().equality().orderAndRange(),

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ catalogs:
1212

1313
security:
1414
'@clerk/nextjs': 6.31.2
15-
next: 15.4.7
15+
next: 15.4.8
1616
vite: 6.4.1

0 commit comments

Comments
 (0)