Skip to content

Commit 74e066c

Browse files
authored
Merge branch 'main' into rob/mobile-594-expo-usesso-sessions-killed-by-lazy-client-rollout
2 parents 51a03c3 + 018d950 commit 74e066c

22 files changed

Lines changed: 245 additions & 326 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
// @ts-expect-error — .mjs plugin has no type declarations
4+
import { applyCatchAllMdReplacements } from '../custom-plugin.mjs';
5+
6+
/**
7+
* Unit coverage for the `getCatchAllReplacements()` rules exercised through the
8+
* exported `applyCatchAllMdReplacements()` entry point.
9+
*/
10+
describe('applyCatchAllMdReplacements', () => {
11+
it('renders a single `@example` as "Example: `value`."', () => {
12+
expect(applyCatchAllMdReplacements('**Example** `foo`')).toBe('Example: `foo`.');
13+
});
14+
15+
it('joins multiple `@example` blocks with ", "', () => {
16+
expect(applyCatchAllMdReplacements('**Examples** `a` `b` `c`')).toBe('Examples: `a`, `b`, `c`.');
17+
});
18+
19+
it('does not corrupt examples that contain internal spaces', () => {
20+
// Regression: splitting the captured group on ' ' rejoined each example's
21+
// internal spaces with ", ", producing a spurious `,,` inside array literals.
22+
const input = '**Examples** `["/orgs/:slug", "/orgs/:slug/(.*)"]` `["/orgs/:id", "/orgs/:id/(.*)"]`';
23+
expect(applyCatchAllMdReplacements(input)).toBe(
24+
'Examples: `["/orgs/:slug", "/orgs/:slug/(.*)"]`, `["/orgs/:id", "/orgs/:id/(.*)"]`.',
25+
);
26+
});
27+
});

.typedoc/custom-plugin.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ function getCatchAllReplacements() {
395395
*/
396396
pattern: /\*\*Examples\*\* ((?:`[^`]+`)(?: `[^`]+`)*)/g,
397397
replace: (/** @type {string} */ _match, /** @type {string} */ capturedGroup) => {
398-
return `Examples: ${capturedGroup.split(' ').join(', ')}.`;
398+
// Match backtick-delimited examples individually; splitting on ' ' breaks examples with internal spaces.
399+
const examples = capturedGroup.match(/`[^`]+`/g) ?? [];
400+
return `Examples: ${examples.join(', ')}.`;
399401
},
400402
},
401403
];

integration/templates/astro-node/astro.config.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import node from '@astrojs/node';
33
import clerk from '@clerk/astro';
44
import react from '@astrojs/react';
55

6-
import tailwind from '@astrojs/tailwind';
7-
86
export default defineConfig({
97
output: 'server',
108
adapter: node({
@@ -19,7 +17,6 @@ export default defineConfig({
1917
},
2018
}),
2119
react(),
22-
tailwind(),
2320
],
2421
server: {
2522
port: process.env.PORT ? Number(process.env.PORT) : undefined,

integration/templates/astro-node/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
"start": "astro dev --port $PORT"
1111
},
1212
"dependencies": {
13-
"@astrojs/check": "^0.9.4",
14-
"@astrojs/node": "^9.0.0",
15-
"@astrojs/react": "^4.0.0",
16-
"@astrojs/tailwind": "^5.1.3",
13+
"@astrojs/check": "^0.9.9",
14+
"@astrojs/node": "^11.0.0",
15+
"@astrojs/react": "^6.0.0",
1716
"@types/react": "18.3.7",
1817
"@types/react-dom": "18.3.0",
19-
"astro": "^5.15.9",
18+
"astro": "^7.0.2",
2019
"react": "18.3.1",
2120
"react-dom": "18.3.1",
22-
"tailwindcss": "^3.4.17",
2321
"typescript": "^5.7.3"
2422
}
2523
}

integration/templates/astro-node/src/middleware.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
1-
import { clerkMiddleware, createRouteMatcher } from '@clerk/astro/server';
2-
3-
const unautorized = () =>
4-
new Response(JSON.stringify({ error: 'unathorized access' }), {
5-
status: 401,
6-
});
7-
8-
/**
9-
* 3. Support handler
10-
*/
11-
const isProtectedPage = createRouteMatcher(['/user(.*)', '/discover(.*)']);
12-
13-
const isProtectedApiRoute = createRouteMatcher(['/api/protected(.*)']);
1+
import { clerkMiddleware } from '@clerk/astro/server';
142

153
export const onRequest = clerkMiddleware((auth, context, next) => {
164
const requestURL = new URL(context.request.url);
17-
if (['/sign-in', '/', '/sign-up'].includes(requestURL.pathname)) {
18-
return next();
19-
}
20-
21-
if (isProtectedApiRoute(context.request) && !auth().userId) {
22-
return unautorized();
23-
}
24-
25-
if (isProtectedPage(context.request) && !auth().userId) {
26-
return auth().redirectToSignIn();
27-
}
285

29-
if (!auth().orgId && requestURL.pathname !== '/discover' && requestURL.pathname === '/organization') {
30-
if (!auth().userId) {
31-
return next();
32-
}
6+
if (requestURL.pathname === '/organization' && auth().userId && !auth().orgId) {
337
const searchParams = new URLSearchParams({
348
redirectUrl: requestURL.href,
359
});

integration/templates/astro-node/src/pages/api/protected/current-org.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type { APIRoute } from 'astro';
22
import { clerkClient } from '@clerk/astro/server';
33

4-
const empty = () => new Response(null);
5-
64
export const GET: APIRoute = async context => {
75
const { locals } = context;
86
const { userId, orgId } = locals.auth();
97
if (!userId) {
10-
// We are handling this at the middleware level
11-
return empty();
8+
return new Response(JSON.stringify({ error: 'unauthorized access' }), {
9+
status: 401,
10+
});
1211
}
1312

1413
if (!orgId) {

integration/templates/astro-node/src/pages/api/protected/only-admin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export const GET: APIRoute = async context => {
55
const { locals } = context;
66
const { auth } = locals;
77

8+
if (!auth().userId) {
9+
return new Response(JSON.stringify({ error: 'unauthorized access' }), {
10+
status: 401,
11+
});
12+
}
13+
814
if (auth().has({ role: 'org:admin' })) {
915
return new Response(
1016
JSON.stringify(

integration/templates/astro-node/src/pages/discover.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
---
22
import { OrganizationList } from '@clerk/astro/components';
33
import Layout from '../layouts/Layout.astro';
4+
5+
const { userId, redirectToSignIn } = Astro.locals.auth();
6+
7+
if (!userId) {
8+
return redirectToSignIn();
9+
}
410
---
511

612
<Layout title='Welcome to Astro.'>

integration/templates/astro-node/src/pages/user.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import { UserProfile } from '@clerk/astro/components';
33
import Layout from '../layouts/Layout.astro';
44
import StreamUser from '../components/StreamUser.astro';
5+
6+
const { userId, redirectToSignIn } = Astro.locals.auth();
7+
8+
if (!userId) {
9+
return redirectToSignIn();
10+
}
511
---
612

713
<Layout title='Welcome to Astro.'>

integration/templates/astro-node/tailwind.config.cjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)