Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekradko committed Oct 10, 2024
1 parent 298a53b commit 63ebdf9
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { auth } from '@clerk/nextjs/server';

export async function GET() {
const { protect } = await auth();
const { userId } = protect(has => has({ role: 'admin' }) || has({ role: 'org:editor' }));
const { userId } = await auth.protect((has: any) => has({ role: 'admin' }) || has({ role: 'org:editor' }));
return new Response(JSON.stringify({ userId }));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default function Home({ params }: { params: { id: string } }) {
const { orgId } = auth();
export default async function Home({ params }: { params: { id: string } }) {
const { orgId } = await auth();

if (params.id != orgId) {
console.log('Mismatch - returning nothing for now...', params.id, orgId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default function Home({ params }: { params: { id: string } }) {
const { orgId } = auth();
export default async function Home({ params }: { params: { id: string } }) {
const { orgId } = await auth();

if (params.id != orgId) {
console.log('Mismatch - returning nothing for now...', params.id, orgId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default function Home({ params }: { params: { slug: string } }) {
const { orgSlug } = auth();
export default async function Home({ params }: { params: { slug: string } }) {
const { orgSlug } = await auth();

if (params.slug != orgSlug) {
console.log('Mismatch - returning nothing for now...', params.slug, orgSlug);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default function Home({ params }: { params: { slug: string } }) {
const { orgSlug } = auth();
export default async function Home({ params }: { params: { slug: string } }) {
const { orgSlug } = await auth();

if (params.slug != orgSlug) {
console.log('Mismatch - returning nothing for now...', params.slug, orgSlug);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default async function Page() {
const { protect } = await auth();
protect();
await auth.protect();

return <div>Protected Page</div>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from '@clerk/nextjs/server';

export default function Home(): {} {
const { orgId } = auth();
export default async function Home() {
const { orgId } = await auth();

if (orgId != null) {
console.log('Oh no, this page should only activate on the personal account!');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { auth } from '@clerk/nextjs/server';

export default async function Page() {
const { protect } = await auth();
protect({ role: 'admin' });
await auth.protect({ role: 'admin' });
return <p>User has access</p>;
}
3 changes: 1 addition & 2 deletions integration/templates/next-app-router/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const isCSPRoute = createRouteMatcher(['/csp']);

export default clerkMiddleware(async (auth, req) => {
if (isProtectedRoute(req)) {
const { protect } = await auth();
protect();
auth().protect();
}

if (isCSPRoute(req)) {
Expand Down
7 changes: 3 additions & 4 deletions integration/tests/dynamic-keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ test.describe('dynamic keys @nextjs', () => {
export default clerkMiddleware(async (auth, request) => {
if (isProtectedRoute(request)) {
const { protect } = await auth();
protect();
auth().protect();
}
if (shouldFetchBapi(request)){
Expand Down Expand Up @@ -65,7 +64,7 @@ test.describe('dynamic keys @nextjs', () => {
await app.teardown();
});

test('redirects to `signInUrl` on `await auth().protect()`', async ({ page, context }) => {
test('redirects to `signInUrl` on `await auth.protect()`', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });

await u.page.goToAppHome();
Expand All @@ -77,7 +76,7 @@ test.describe('dynamic keys @nextjs', () => {
await u.page.waitForURL(/foobar/);
});

test('resolves auth signature with `secretKey` on `await auth().protect()`', async ({ page, context }) => {
test('resolves auth signature with `secretKey` on `await auth.protect()`', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToRelative('/page-protected');
await u.page.waitForURL(/foobar/);
Expand Down

0 comments on commit 63ebdf9

Please sign in to comment.