Skip to content

Commit 9759733

Browse files
committed
fixes
1 parent a0da3f0 commit 9759733

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

integration/templates/express-vite/src/client/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ document.addEventListener('DOMContentLoaded', async function () {
99
await clerk.load({
1010
ui: { ClerkUI },
1111
});
12+
// @ts-expect-error: Make waitForSession test utility work
13+
window.Clerk = clerk;
1214

1315
if (clerk.isSignedIn) {
1416
document.getElementById('app')!.innerHTML = `

integration/templates/hono-vite/src/client/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ document.addEventListener('DOMContentLoaded', async function () {
99
await clerk.load({
1010
ui: { ClerkUI },
1111
});
12+
// @ts-expect-error: Make waitForSession test utility work
13+
window.Clerk = clerk;
1214

1315
if (clerk.isSignedIn) {
1416
document.getElementById('app')!.innerHTML = `

integration/tests/hono/machine.test.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import {
88
registerOAuthAuthTests,
99
} from '../../testUtils/machineAuthHelpers';
1010

11-
const createAppFile = (routes: string) => `
11+
const createAppFile = (routes: string, middlewareOptions = '') => `
1212
import { clerkMiddleware, getAuth } from '@clerk/hono';
1313
import { Hono } from 'hono';
1414
1515
const app = new Hono();
1616
17-
app.use('*', clerkMiddleware());
17+
app.use(
18+
'*',
19+
clerkMiddleware({
20+
publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY,
21+
${middlewareOptions}
22+
}),
23+
);
1824
1925
${routes}
2026
@@ -24,11 +30,20 @@ export default app;
2430
const createMainFile = () => `
2531
import 'dotenv/config';
2632
27-
import { serve } from '@hono/node-server';
33+
import { getRequestListener } from '@hono/node-server';
34+
import express from 'express';
35+
import ViteExpress from 'vite-express';
2836
import app from './app';
2937
38+
const expressApp = express();
39+
const honoRequestListener = getRequestListener(app.fetch);
40+
41+
expressApp.use('/api', async (req: any, res: any) => {
42+
await honoRequestListener(req, res);
43+
});
44+
3045
const port = parseInt(process.env.PORT as string) || 3002;
31-
serve({ fetch: app.fetch, port }, () => console.log(\`Server is listening on port \${port}...\`));
46+
ViteExpress.listen(expressApp, port, () => console.log(\`Server is listening on port \${port}...\`));
3247
`;
3348

3449
const adapter: MachineAuthTestAdapter = {
@@ -39,7 +54,7 @@ const adapter: MachineAuthTestAdapter = {
3954
config
4055
.addFile('src/server/app.ts', () =>
4156
createAppFile(`
42-
app.get('/api/me', c => {
57+
app.get('/me', c => {
4358
const { userId, tokenType } = getAuth(c, { acceptsToken: 'api_key' });
4459
4560
if (!userId) {
@@ -49,7 +64,7 @@ app.get('/api/me', c => {
4964
return c.json({ userId, tokenType });
5065
});
5166
52-
app.post('/api/me', c => {
67+
app.post('/me', c => {
5368
const authObject = getAuth(c, { acceptsToken: ['api_key', 'session_token'] });
5469
5570
if (!authObject.isAuthenticated) {
@@ -67,17 +82,20 @@ app.post('/api/me', c => {
6782
addRoutes: config =>
6883
config
6984
.addFile('src/server/app.ts', () =>
70-
createAppFile(`
71-
app.get('/api/m2m', c => {
72-
const { subject, tokenType, isAuthenticated } = getAuth(c, { acceptsToken: 'm2m_token' });
85+
createAppFile(
86+
`
87+
app.get('/m2m', c => {
88+
const { subject, tokenType, machineId } = getAuth(c, { acceptsToken: 'm2m_token' });
7389
74-
if (!isAuthenticated) {
90+
if (!machineId) {
7591
return c.text('Unauthorized', 401);
7692
}
7793
7894
return c.json({ subject, tokenType });
7995
});
80-
`),
96+
`,
97+
`machineSecretKey: process.env.CLERK_MACHINE_SECRET_KEY || '',`,
98+
),
8199
)
82100
.addFile('src/server/main.ts', () => createMainFile()),
83101
},
@@ -88,7 +106,7 @@ app.get('/api/m2m', c => {
88106
config
89107
.addFile('src/server/app.ts', () =>
90108
createAppFile(`
91-
app.get('/api/oauth-verify', c => {
109+
app.get('/oauth-verify', c => {
92110
const { userId, tokenType } = getAuth(c, { acceptsToken: 'oauth_token' });
93111
94112
if (!userId) {
@@ -98,7 +116,7 @@ app.get('/api/oauth-verify', c => {
98116
return c.json({ userId, tokenType });
99117
});
100118
101-
app.get('/api/oauth/callback', c => {
119+
app.get('/oauth/callback', c => {
102120
return c.json({ message: 'OAuth callback received' });
103121
});
104122
`),

0 commit comments

Comments
 (0)