Skip to content

Commit

Permalink
cleanup unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Oct 3, 2024
1 parent 77c58d3 commit 8c336ab
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 111 deletions.
28 changes: 0 additions & 28 deletions packages/nextjs/src/app-router/server/controlComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { __internal_findFailedProtectConfiguration } from '@clerk/shared';
import type {
__experimental_SessionVerificationLevel,
Autocomplete,
CheckAuthorizationWithCustomPermissions,
OrganizationCustomPermissionKey,
OrganizationCustomRoleKey,
} from '@clerk/types';
Expand Down Expand Up @@ -97,28 +96,18 @@ type NonNullableRecord<T, K extends keyof T> = {

type WithProtectComponentParams =
| {
condition?: never;
role: OrganizationCustomRoleKey;
permission?: never;
reverification?: never;
fallback?: React.ComponentType | string;
}
| {
condition?: never;
role?: never;
permission: OrganizationCustomPermissionKey;
reverification?: never;
fallback?: React.ComponentType | string;
}
| {
condition: (has: CheckAuthorizationWithCustomPermissions) => boolean;
role?: never;
permission?: never;
reverification?: never;
fallback?: React.ComponentType;
}
| {
condition?: never;
role?: never;
permission?: never;
reverification:
Expand Down Expand Up @@ -232,10 +221,6 @@ function __experimental_protectComponent(params?: ProtectComponentParams) {
if (failedItem?.fallback) {
const Fallback = failedItem.fallback;

if (Fallback === 'modal') {
return <UserVerificationModal />;
}

if (Fallback === 'redirectToSignIn') {
_auth.redirectToSignIn();
}
Expand All @@ -248,26 +233,13 @@ function __experimental_protectComponent(params?: ProtectComponentParams) {
throw 'not valid';
}

if (!failedItem.reverification) {
return (
// @ts-expect-error type props
<Fallback
{
// Could this be unsafe ?
...props
}
/>
);
}

return (
// @ts-expect-error type props
<Fallback
{
// Could this be unsafe ?
...props
}
UserVerificationTrigger={UserVerificationTrigger}
/>
);
}
Expand Down
40 changes: 0 additions & 40 deletions packages/nextjs/src/server/protectAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ProtectConfiguration } from '@clerk/shared/protect';
import { __internal_findFailedProtectConfiguration } from '@clerk/shared/protect';
import type {
__experimental_SessionVerificationLevel,
CheckAuthorizationWithCustomPermissions,
OrganizationCustomPermissionKey,
OrganizationCustomRoleKey,
} from '@clerk/types';
Expand All @@ -24,25 +23,16 @@ type NonNullableRecord<T, K extends keyof T> = {

type WithProtectActionParams =
| {
condition?: never;
role: OrganizationCustomRoleKey;
permission?: never;
reverification?: never;
}
| {
condition?: never;
role?: never;
permission: OrganizationCustomPermissionKey;
reverification?: never;
}
| {
condition: (has: CheckAuthorizationWithCustomPermissions) => boolean;
role?: never;
permission?: never;
reverification?: never;
}
| {
condition?: never;
role?: never;
permission?: never;
reverification:
Expand Down Expand Up @@ -84,15 +74,10 @@ function protectAction() {
| Promise<
InferStrictTypeParams<T> extends { reverification: any }
? {
// a: InferStrictTypeParams<T>;
clerk_error: {
type: 'forbidden';
reason: 'assurance';
metadata: Omit<InferStrictTypeParams<T>, 'fallback'>;
// {
// level: __experimental_SessionVerificationLevel;
// maxAge: __experimental_SessionVerificationMaxAge;
// };
};
}
: InferStrictTypeParams<T> extends
Expand Down Expand Up @@ -180,31 +165,6 @@ function protectAction() {
const _auth = auth();
const failedItem = __internal_findFailedProtectConfiguration(configs, _auth);

if (failedItem?.reverification) {
const errorObj = {
clerk_error: {
type: 'forbidden',
reason: 'assurance',
metadata: failedItem.reverification,
},
} as const;

//@ts-ignore
return errorObj;
}

if (failedItem?.role || failedItem?.permission) {
// What should we do here ?
return {
//@ts-ignore
clerk_error: {
type: 'something',
reason: 'something',
metadata: failedItem,
},
};
}

if (failedItem) {
return {
//@ts-ignore
Expand Down
44 changes: 2 additions & 42 deletions packages/nextjs/src/server/protectRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ProtectConfiguration } from '@clerk/shared/protect';
import { __internal_findFailedProtectConfiguration } from '@clerk/shared/protect';
import type {
__experimental_SessionVerificationLevel,
CheckAuthorizationWithCustomPermissions,
OrganizationCustomPermissionKey,
OrganizationCustomRoleKey,
} from '@clerk/types';
Expand All @@ -21,25 +20,16 @@ type NonNullableRecord<T, K extends keyof T> = {

type WithProtectActionParams =
| {
condition?: never;
role: OrganizationCustomRoleKey;
permission?: never;
reverification?: never;
}
| {
condition?: never;
role?: never;
permission: OrganizationCustomPermissionKey;
reverification?: never;
}
| {
condition: (has: CheckAuthorizationWithCustomPermissions) => boolean;
role?: never;
permission?: never;
reverification?: never;
}
| {
condition?: never;
role?: never;
permission?: never;
reverification:
Expand Down Expand Up @@ -122,7 +112,7 @@ function protectRoute() {
},
}),
{
status: 403,
status: 401,
},
);
}
Expand All @@ -147,36 +137,6 @@ function protectRoute() {
const _auth = auth();
const failedItem = __internal_findFailedProtectConfiguration(configs, _auth);

if (failedItem?.reverification) {
const errorObj = {
clerk_error: {
type: 'forbidden',
reason: 'assurance',
metadata: failedItem.reverification,
},
} as const;

return new Response(JSON.stringify(errorObj), {
status: 403,
});
}

if (failedItem?.role || failedItem?.permission) {
// What should we do here ?
return new Response(
JSON.stringify({
clerk_error: {
type: 'something',
reason: 'something',
metadata: failedItem,
},
}),
{
status: 403,
},
);
}

if (failedItem) {
return new Response(
JSON.stringify({
Expand All @@ -186,7 +146,7 @@ function protectRoute() {
},
}),
{
status: 403,
status: 401,
},
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export {
SignedOut,
SignedIn,
Protect,
// protect as __experimental_protect,
__experimental_protectComponent,
RedirectToSignIn,
RedirectToSignUp,
Expand Down

0 comments on commit 8c336ab

Please sign in to comment.