Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/shy-onions-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@clerk/astro': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
'@clerk/vue': minor
---

Update `has` from `useAuth()` to always be a function.
Previously `has` would be `undefined` when `isLoaded:false`, now it will be a function that always returns false.
68 changes: 2 additions & 66 deletions packages/astro/src/react/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import type {
ActJWTClaim,
CheckAuthorizationWithCustomPermissions,
Clerk,
GetToken,
OrganizationCustomRoleKey,
SignOut,
} from '@clerk/types';
import type { CheckAuthorizationWithCustomPermissions, Clerk, GetToken, SignOut, UseAuthReturn } from '@clerk/types';
import type { Store, StoreValue } from 'nanostores';
import { useCallback, useSyncExternalStore } from 'react';

Expand All @@ -14,9 +7,6 @@ import { authAsyncStorage } from '#async-local-storage';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;

/**
* @internal
*/
Expand Down Expand Up @@ -53,60 +43,6 @@ const createSignOut = () => {
};
};

type UseAuthReturn =
| {
isLoaded: false;
isSignedIn: undefined;
userId: undefined;
sessionId: undefined;
actor: undefined;
orgId: undefined;
orgRole: undefined;
orgSlug: undefined;
has: CheckAuthorizationSignedOut;
signOut: SignOut;
getToken: GetToken;
}
| {
isLoaded: true;
isSignedIn: false;
userId: null;
sessionId: null;
actor: null;
orgId: null;
orgRole: null;
orgSlug: null;
has: CheckAuthorizationWithoutOrgOrUser;
signOut: SignOut;
getToken: GetToken;
}
| {
isLoaded: true;
isSignedIn: true;
userId: string;
sessionId: string;
actor: ActJWTClaim | null;
orgId: null;
orgRole: null;
orgSlug: null;
has: CheckAuthorizationWithoutOrgOrUser;
signOut: SignOut;
getToken: GetToken;
}
| {
isLoaded: true;
isSignedIn: true;
userId: string;
sessionId: string;
actor: ActJWTClaim | null;
orgId: string;
orgRole: OrganizationCustomRoleKey;
orgSlug: string | null;
has: CheckAuthorizationWithCustomPermissions;
signOut: SignOut;
getToken: GetToken;
};

type UseAuth = () => UseAuthReturn;

/**
Expand Down Expand Up @@ -178,7 +114,7 @@ export const useAuth: UseAuth = () => {
orgId: undefined,
orgRole: undefined,
orgSlug: undefined,
has: undefined,
has: () => false,
signOut,
getToken,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function useDerivedAuth(authObject: any): UseAuthReturn {
orgId: undefined,
orgRole: undefined,
orgSlug: undefined,
has: undefined,
has: () => false,
signOut,
getToken,
};
Expand Down
7 changes: 3 additions & 4 deletions packages/types/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import type {
import type { SignUpResource } from './signUp';
import type { UserResource } from './user';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
type CheckAuthorizationWithoutUser = (params: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;

/**
* Return values of the `useAuth()` hook
Expand Down Expand Up @@ -53,7 +52,7 @@ export type UseAuthReturn =
/**
* A function that checks if the user has specific permissions or roles. See the [reference doc](https://clerk.com/docs/references/backend/types/auth-object#has).
*/
has: CheckAuthorizationSignedOut;
has: CheckAuthorizationWithoutUser;
/**
* A function that signs out the current user. Returns a promise that resolves when complete. See the [reference doc](https://clerk.com/docs/references/javascript/clerk/clerk#sign-out).
*/
Expand All @@ -72,7 +71,7 @@ export type UseAuthReturn =
orgId: null;
orgRole: null;
orgSlug: null;
has: CheckAuthorizationWithoutOrgOrUser;
has: CheckAuthorizationWithoutUser;
signOut: SignOut;
getToken: GetToken;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/composables/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const useAuth: UseAuth = () => {
orgId: undefined,
orgRole: undefined,
orgSlug: undefined,
has: undefined,
has: () => false,
signOut,
getToken,
};
Expand Down Expand Up @@ -158,7 +158,7 @@ export const useAuth: UseAuth = () => {
orgId: null,
orgRole: null,
orgSlug: null,
has: () => false,
has,
signOut,
getToken,
};
Expand Down
Loading