Skip to content

Commit

Permalink
feat: vscode jest open test result view on test fails and add unauthe…
Browse files Browse the repository at this point in the history
…nticatedUrl in clerk middleware
  • Loading branch information
ixartz committed May 17, 2024
1 parent f1af4e3 commit 3cfcb6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"testFileOnly": true,
"coverage": true
}, // Configure Jest extension
"jest.outputConfig": {
"revealOn": "error",
"revealWithFocus": "test-results",
"clearOnRun": "none"
}, // Switch to test-results view when test fails
"testing.openTesting": "neverOpen", // For a consistent Jest output experience, the simplest solution is to set to "neverOpen"
// Multiple language settings for json and jsonc files
"[json][jsonc][yaml]": {
"editor.formatOnSave": true,
Expand Down
12 changes: 11 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ export default function middleware(
return clerkMiddleware((auth, req) => {
const authObj = auth();

if (isProtectedRoute(req)) authObj.protect();
if (isProtectedRoute(req)) {
const locale =
req.nextUrl.pathname.match(/(\/.*)\/dashboard/)?.at(1) ?? '';

const signInUrl = new URL(`${locale}/sign-in`, req.url);

authObj.protect({
// `unauthenticatedUrl` is needed to avoid error: "Unable to find `next-intl` locale because the middleware didn't run on this request"
unauthenticatedUrl: signInUrl.toString(),
});
}

if (
authObj.userId &&
Expand Down

0 comments on commit 3cfcb6b

Please sign in to comment.