Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 469
chore(repo): Add Express SDK E2E tests#6499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a9787efdc8c7be58191b11707c1256867b2757ea76dc77a3febff1494f0bd61ebd8b96173be5eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/express': patch | ||
| --- | ||
| Deprecates `enableHandshake` option in `clerkMiddleware`. This option is unnecessary for API requests since they don't trigger handshake flows. The option will be removed in a future version. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Vite + TS + Express</title> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/client/main.ts"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Clerk } from '@clerk/clerk-js'; | ||
| const publishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY; | ||
| document.addEventListener('DOMContentLoaded', async function () { | ||
| const clerk = new Clerk(publishableKey); | ||
| await clerk.load(); | ||
| if (clerk.isSignedIn) { | ||
| document.getElementById('app')!.innerHTML = ` | ||
| <div id="user-button"></div> | ||
| `; | ||
wobsoriano marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const userButtonDiv = document.getElementById('user-button'); | ||
| clerk.mountUserButton(userButtonDiv); | ||
| } else { | ||
| document.getElementById('app')!.innerHTML = ` | ||
| <div id="sign-in"></div> | ||
| `; | ||
| const signInDiv = document.getElementById('sign-in'); | ||
| clerk.mountSignIn(signInDiv); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler" | ||
| } | ||
wobsoriano marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /// <reference types="vite/client" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,44 @@ | ||
| // Should be at the top of the file - used to load clerk secret key | ||
| import 'dotenv/config'; | ||
| import { clerkMiddleware } from '@clerk/express'; | ||
| import { clerkMiddleware, getAuth } from '@clerk/express'; | ||
| import express from 'express'; | ||
| import ViteExpress from 'vite-express'; | ||
| const app = express(); | ||
| app.use(clerkMiddleware()); | ||
| app.set('view engine', 'ejs'); | ||
| app.set('views', 'src/views'); | ||
| app.use( | ||
| clerkMiddleware({ | ||
| publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY, | ||
| }), | ||
wobsoriano marked this conversation as resolved.
Dismissed
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
| app.get('/api/protected', (req: any, res: any, _next: any) => { | ||
| const { userId } = getAuth(req); | ||
| if (!userId) { | ||
| res.status(401).send('Unauthorized'); | ||
| return; | ||
| } | ||
| res.send('Protected API response'); | ||
| }); | ||
wobsoriano marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const legacyRequireAuth = (req: any, _res: any, next: any) => { | ||
| if (!req.auth.userId) { | ||
| return next(new Error('Unauthenticated')); | ||
| return next(new Error('Unauthorized')); | ||
| } | ||
| next(); | ||
| }; | ||
| app.get('/api/protected', legacyRequireAuth, (_req: any, res: any, _next: any) => { | ||
| return res.send('Protected API response'); | ||
| }); | ||
| app.get('/sign-in', (_req: any, res: any) => { | ||
| return res.render('sign-in.ejs', { | ||
| publishableKey: process.env.CLERK_PUBLISHABLE_KEY, | ||
| signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
| }); | ||
| }); | ||
| app.get('/', (_req: any, res: any) => { | ||
| return res.render('index.ejs', { | ||
| publishableKey: process.env.CLERK_PUBLISHABLE_KEY, | ||
| signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
| }); | ||
| }); | ||
| app.get('/sign-up', (_req: any, res: any) => { | ||
| return res.render('sign-up.ejs', { | ||
| publishableKey: process.env.CLERK_PUBLISHABLE_KEY, | ||
| signUpUrl: process.env.CLERK_SIGN_UP_URL, | ||
| }); | ||
| }); | ||
| app.get('/protected', (_req: any, res: any) => { | ||
| return res.render('protected.ejs', { | ||
| publishableKey: process.env.CLERK_PUBLISHABLE_KEY, | ||
| signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
| signUpUrl: process.env.CLERK_SIGN_UP_URL, | ||
| }); | ||
| app.get('/api/legacy/protected', legacyRequireAuth, (_req: any, res: any, _next: any) => { | ||
| res.send('Protected API response'); | ||
| }); | ||
| // Handle authentication error, otherwise application will crash | ||
| // @ts-ignore | ||
| app.use((err, req, res, next) => { | ||
| if (err) { | ||
| console.error(err); | ||
| res.status(401).end(); | ||
| res.status(401).send('Unauthorized'); | ||
| return; | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,18 +2,18 @@ | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
| "allowJs": false, | ||
| "skipLibCheck": true, | ||
| "esModuleInterop": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "module": "NodeNext", | ||
| "lib": ["ESNext", "DOM"], | ||
wobsoriano marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "moduleResolution": "NodeNext", | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "module": "CommonJS", | ||
| "moduleResolution": "Node", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true | ||
| "esModuleInterop": true, | ||
| "noEmit": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "noImplicitReturns": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["src"] | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.