diff --git a/packages/backend/src/tokens/authObjects.ts b/packages/backend/src/tokens/authObjects.ts index 7baeea67ab..3d831d2f45 100644 --- a/packages/backend/src/tokens/authObjects.ts +++ b/packages/backend/src/tokens/authObjects.ts @@ -14,6 +14,7 @@ import { createBackendApiClient } from '../api'; type AuthObjectDebugData = Record; type CreateAuthObjectDebug = (data?: AuthObjectDebugData) => AuthObjectDebug; type AuthObjectDebug = () => AuthObjectDebugData; +type CheckAuthorizationSignedOut = undefined; export type SignedInAuthObjectOptions = CreateBackendApiOptions & { token: string; @@ -52,7 +53,7 @@ export type SignedOutAuthObject = { orgPermissions: null; organization: null; getToken: ServerGetToken; - has: CheckAuthorizationWithCustomPermissions; + has: CheckAuthorizationSignedOut; debug: AuthObjectDebug; }; @@ -126,7 +127,7 @@ export function signedOutAuthObject(debugData?: AuthObjectDebugData): SignedOutA orgPermissions: null, organization: null, getToken: () => Promise.resolve(null), - has: () => false, + has: undefined, debug: createDebug(debugData), }; } diff --git a/packages/nextjs/src/app-router/server/controlComponents.tsx b/packages/nextjs/src/app-router/server/controlComponents.tsx index aed6511fee..5647d8f199 100644 --- a/packages/nextjs/src/app-router/server/controlComponents.tsx +++ b/packages/nextjs/src/app-router/server/controlComponents.tsx @@ -47,13 +47,13 @@ export function Protect(props: ProtectServerComponentProps) { * Check against the results of `has` called inside the callback */ if (typeof restAuthorizedParams.condition === 'function') { - if (restAuthorizedParams.condition(has)) { + if (userId && restAuthorizedParams.condition(has)) { return <>{children}; } return <>{fallback ?? null}; } - if (has(restAuthorizedParams)) { + if (userId && has(restAuthorizedParams)) { return <>{children}; } diff --git a/packages/react/src/components/controlComponents.tsx b/packages/react/src/components/controlComponents.tsx index f37e147fd7..ffdb1a3fc3 100644 --- a/packages/react/src/components/controlComponents.tsx +++ b/packages/react/src/components/controlComponents.tsx @@ -102,13 +102,13 @@ export const Protect = ({ children, fallback, ...restAuthorizedParams }: Protect * Check against the results of `has` called inside the callback */ if (typeof restAuthorizedParams.condition === 'function') { - if (restAuthorizedParams.condition(has)) { + if (userId && restAuthorizedParams.condition(has)) { return <>{children}; } return <>{fallback ?? null}; } - if (has(restAuthorizedParams)) { + if (userId && has(restAuthorizedParams)) { return <>{children}; } diff --git a/packages/react/src/hooks/useAuth.ts b/packages/react/src/hooks/useAuth.ts index 2c8e1a9904..3781db518c 100644 --- a/packages/react/src/hooks/useAuth.ts +++ b/packages/react/src/hooks/useAuth.ts @@ -13,7 +13,8 @@ import { invalidStateError, useAuthHasRequiresRoleOrPermission } from '../errors import { errorThrower } from '../utils'; import { createGetToken, createSignOut } from './utils'; -type CheckAuthorizationSignedOut = (params?: Parameters[0]) => false; +type CheckAuthorizationSignedOut = undefined; +type CheckAuthorizationWithoutOrg = (params?: Parameters[0]) => false; type UseAuthReturn = | { @@ -51,7 +52,7 @@ type UseAuthReturn = orgId: null; orgRole: null; orgSlug: null; - has: CheckAuthorizationSignedOut; + has: CheckAuthorizationWithoutOrg; signOut: SignOut; getToken: GetToken; } @@ -147,7 +148,7 @@ export const useAuth: UseAuth = () => { orgId: undefined, orgRole: undefined, orgSlug: undefined, - has: () => false, + has: undefined, signOut, getToken, }; @@ -163,7 +164,7 @@ export const useAuth: UseAuth = () => { orgId: null, orgRole: null, orgSlug: null, - has: () => false, + has: undefined, signOut, getToken, };