@better-auth-ui/react 1.6.31 → 1.6.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +340 -282
- package/dist/lib/auth-client.d.ts +8 -1
- package/dist/mutations/admin/stop-impersonating-mutation.d.ts +61 -0
- package/dist/mutations/oauth-provider/oauth-consent-mutation.d.ts +40 -0
- package/dist/mutations/organization/accept-invitation-mutation.d.ts +4 -4
- package/dist/mutations/organization/cancel-invitation-mutation.d.ts +4 -4
- package/dist/mutations/organization/invite-member-mutation.d.ts +8 -8
- package/dist/mutations/organization/leave-organization-mutation.d.ts +2 -2
- package/dist/mutations/organization/reject-invitation-mutation.d.ts +2 -2
- package/dist/mutations/organization/remove-member-mutation.d.ts +2 -2
- package/dist/mutations/organization/set-active-organization-mutation.d.ts +6 -6
- package/dist/queries/oauth-provider/public-oauth-client-query.d.ts +33 -0
- package/dist/queries/organization/list-members-query.d.ts +4 -4
- package/dist/server/queries/organization/list-members-query.d.ts +4 -4
- package/package.json +3 -1
- package/src/index.ts +3 -0
- package/src/lib/auth-client.ts +15 -0
- package/src/mutations/admin/stop-impersonating-mutation.ts +71 -0
- package/src/mutations/oauth-provider/oauth-consent-mutation.ts +41 -0
- package/src/queries/oauth-provider/public-oauth-client-query.ts +131 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { apiKeyClient } from '@better-auth/api-key/client';
|
|
2
|
+
import { oauthProviderClient } from '@better-auth/oauth-provider/client';
|
|
2
3
|
import { passkeyClient } from '@better-auth/passkey/client';
|
|
3
|
-
import { deviceAuthorizationClient, lastLoginMethodClient, magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
|
|
4
|
+
import { AdminClientOptions, adminClient, deviceAuthorizationClient, lastLoginMethodClient, magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
|
|
4
5
|
import { createAuthClient } from 'better-auth/react';
|
|
5
6
|
export type AuthClient = ReturnType<typeof createAuthClient>;
|
|
7
|
+
export type AdminAuthClient = ReturnType<typeof createAuthClient<{
|
|
8
|
+
plugins: [ReturnType<typeof adminClient<AdminClientOptions>>];
|
|
9
|
+
}>>;
|
|
6
10
|
export type MagicLinkAuthClient = ReturnType<typeof createAuthClient<{
|
|
7
11
|
plugins: [ReturnType<typeof magicLinkClient>];
|
|
8
12
|
}>>;
|
|
@@ -21,6 +25,9 @@ export type PasskeyAuthClient = ReturnType<typeof createAuthClient<{
|
|
|
21
25
|
export type ApiKeyAuthClient = ReturnType<typeof createAuthClient<{
|
|
22
26
|
plugins: [ReturnType<typeof apiKeyClient>];
|
|
23
27
|
}>>;
|
|
28
|
+
export type OAuthProviderAuthClient = ReturnType<typeof createAuthClient<{
|
|
29
|
+
plugins: [ReturnType<typeof oauthProviderClient>];
|
|
30
|
+
}>>;
|
|
24
31
|
export type UsernameAuthClient = ReturnType<typeof createAuthClient<{
|
|
25
32
|
plugins: [ReturnType<typeof usernameClient>];
|
|
26
33
|
}>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { AdminAuthClient } from '../../lib/auth-client';
|
|
4
|
+
export type StopImpersonatingParams<TAuthClient extends AdminAuthClient> = Parameters<TAuthClient["admin"]["stopImpersonating"]>[0];
|
|
5
|
+
export type StopImpersonatingOptions<TAuthClient extends AdminAuthClient> = Omit<ReturnType<typeof stopImpersonatingOptions<TAuthClient>>, "mutationKey" | "mutationFn" | "meta">;
|
|
6
|
+
/**
|
|
7
|
+
* Mutation options factory for restoring the administrator's session.
|
|
8
|
+
*
|
|
9
|
+
* @param authClient - The Better Auth client with the admin plugin.
|
|
10
|
+
*/
|
|
11
|
+
export declare function stopImpersonatingOptions<TAuthClient extends AdminAuthClient>(authClient: TAuthClient): import('@tanstack/query-core').WithRequired<import('@tanstack/react-query').UseMutationOptions<{
|
|
12
|
+
session: {
|
|
13
|
+
id: string;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
userId: string;
|
|
17
|
+
expiresAt: Date;
|
|
18
|
+
token: string;
|
|
19
|
+
ipAddress?: string | null | undefined;
|
|
20
|
+
userAgent?: string | null | undefined;
|
|
21
|
+
} & Record<string, any>;
|
|
22
|
+
user: {
|
|
23
|
+
id: string;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
email: string;
|
|
27
|
+
emailVerified: boolean;
|
|
28
|
+
name: string;
|
|
29
|
+
image?: string | null | undefined;
|
|
30
|
+
} & Record<string, any>;
|
|
31
|
+
}, BetterFetchError, StopImpersonatingParams<TAuthClient> | undefined, unknown>, "mutationKey">;
|
|
32
|
+
/**
|
|
33
|
+
* Stop impersonating a user and restore the administrator's session.
|
|
34
|
+
*
|
|
35
|
+
* On success, `MutationInvalidator` awaits invalidation of the session query
|
|
36
|
+
* so every auth surface immediately reflects the restored administrator.
|
|
37
|
+
*
|
|
38
|
+
* @param authClient - The Better Auth client with the admin plugin.
|
|
39
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useStopImpersonating<TAuthClient extends AdminAuthClient>(authClient: TAuthClient, options?: StopImpersonatingOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseMutationResult<{
|
|
42
|
+
session: {
|
|
43
|
+
id: string;
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
updatedAt: Date;
|
|
46
|
+
userId: string;
|
|
47
|
+
expiresAt: Date;
|
|
48
|
+
token: string;
|
|
49
|
+
ipAddress?: string | null | undefined;
|
|
50
|
+
userAgent?: string | null | undefined;
|
|
51
|
+
} & Record<string, any>;
|
|
52
|
+
user: {
|
|
53
|
+
id: string;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
email: string;
|
|
57
|
+
emailVerified: boolean;
|
|
58
|
+
name: string;
|
|
59
|
+
image?: string | null | undefined;
|
|
60
|
+
} & Record<string, any>;
|
|
61
|
+
}, BetterFetchError, StopImpersonatingParams<TAuthClient> | undefined, unknown>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OAuthProviderAuthClient } from '../../lib/auth-client';
|
|
2
|
+
export type OAuthConsentParams<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = Parameters<TAuthClient["oauth2"]["consent"]>[0];
|
|
3
|
+
export type OAuthConsentOptions<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = Omit<ReturnType<typeof oauthConsentOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for accepting or denying an OAuth request.
|
|
6
|
+
*
|
|
7
|
+
* Better Auth reads the signed authorization query from the current URL and
|
|
8
|
+
* validates the resulting redirect.
|
|
9
|
+
*/
|
|
10
|
+
export declare function oauthConsentOptions<TAuthClient extends OAuthProviderAuthClient>(authClient: TAuthClient): import('../auth-mutation-options').AuthMutationOptions<(<FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
11
|
+
accept: boolean;
|
|
12
|
+
scope?: string | undefined;
|
|
13
|
+
oauth_query?: string | undefined;
|
|
14
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
15
|
+
accept: boolean;
|
|
16
|
+
scope?: string | undefined;
|
|
17
|
+
oauth_query?: string | undefined;
|
|
18
|
+
} & {
|
|
19
|
+
fetchOptions?: FetchOptions | undefined;
|
|
20
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<NonNullable<{
|
|
21
|
+
redirect: boolean;
|
|
22
|
+
url: string;
|
|
23
|
+
} | {
|
|
24
|
+
redirect: boolean;
|
|
25
|
+
url: string;
|
|
26
|
+
}>, {
|
|
27
|
+
code?: string | undefined;
|
|
28
|
+
message?: string | undefined;
|
|
29
|
+
}, FetchOptions["throw"] extends true ? true : false>>), readonly ["auth", "oauthProvider", "consent"]>;
|
|
30
|
+
export declare function useOAuthConsent<TAuthClient extends OAuthProviderAuthClient>(authClient: TAuthClient, options?: OAuthConsentOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<any, import('better-auth/client').BetterFetchError, import('better-auth').Prettify<{
|
|
31
|
+
accept: boolean;
|
|
32
|
+
scope?: string | undefined;
|
|
33
|
+
oauth_query?: string | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
fetchOptions?: import('better-auth').ClientFetchOption<Partial<{
|
|
36
|
+
accept: boolean;
|
|
37
|
+
scope?: string | undefined;
|
|
38
|
+
oauth_query?: string | undefined;
|
|
39
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined> | undefined;
|
|
40
|
+
}>, unknown>;
|
|
@@ -8,8 +8,8 @@ export declare function acceptInvitationOptions<TAuthClient extends Organization
|
|
|
8
8
|
id: string;
|
|
9
9
|
organizationId: string;
|
|
10
10
|
email: string;
|
|
11
|
-
role: "
|
|
12
|
-
status: import('better-auth/
|
|
11
|
+
role: "admin" | "member" | "owner";
|
|
12
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
13
13
|
inviterId: string;
|
|
14
14
|
expiresAt: Date;
|
|
15
15
|
createdAt: Date;
|
|
@@ -27,8 +27,8 @@ export declare function useAcceptInvitation<TAuthClient extends OrganizationAuth
|
|
|
27
27
|
id: string;
|
|
28
28
|
organizationId: string;
|
|
29
29
|
email: string;
|
|
30
|
-
role: "
|
|
31
|
-
status: import('better-auth/
|
|
30
|
+
role: "admin" | "member" | "owner";
|
|
31
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
32
32
|
inviterId: string;
|
|
33
33
|
expiresAt: Date;
|
|
34
34
|
createdAt: Date;
|
|
@@ -7,8 +7,8 @@ export declare function cancelInvitationOptions<TAuthClient extends Organization
|
|
|
7
7
|
id: string;
|
|
8
8
|
organizationId: string;
|
|
9
9
|
email: string;
|
|
10
|
-
role: "
|
|
11
|
-
status: import('better-auth/
|
|
10
|
+
role: "admin" | "member" | "owner";
|
|
11
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
12
12
|
inviterId: string;
|
|
13
13
|
expiresAt: Date;
|
|
14
14
|
createdAt: Date;
|
|
@@ -17,8 +17,8 @@ export declare function useCancelInvitation<TAuthClient extends OrganizationAuth
|
|
|
17
17
|
id: string;
|
|
18
18
|
organizationId: string;
|
|
19
19
|
email: string;
|
|
20
|
-
role: "
|
|
21
|
-
status: import('better-auth/
|
|
20
|
+
role: "admin" | "member" | "owner";
|
|
21
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
22
22
|
inviterId: string;
|
|
23
23
|
expiresAt: Date;
|
|
24
24
|
createdAt: Date;
|
|
@@ -7,8 +7,8 @@ export declare function inviteMemberOptions<TAuthClient extends OrganizationAuth
|
|
|
7
7
|
id: string;
|
|
8
8
|
organizationId: string;
|
|
9
9
|
email: string;
|
|
10
|
-
role: "
|
|
11
|
-
status: import('better-auth/
|
|
10
|
+
role: "admin" | "member" | "owner";
|
|
11
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
12
12
|
inviterId: string;
|
|
13
13
|
expiresAt: Date;
|
|
14
14
|
createdAt: Date;
|
|
@@ -16,8 +16,8 @@ export declare function inviteMemberOptions<TAuthClient extends OrganizationAuth
|
|
|
16
16
|
id: string;
|
|
17
17
|
organizationId: string;
|
|
18
18
|
email: string;
|
|
19
|
-
role: "
|
|
20
|
-
status: import('better-auth/
|
|
19
|
+
role: "admin" | "member" | "owner";
|
|
20
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
21
21
|
inviterId: string;
|
|
22
22
|
expiresAt: Date;
|
|
23
23
|
createdAt: Date;
|
|
@@ -26,8 +26,8 @@ export declare function useInviteMember<TAuthClient extends OrganizationAuthClie
|
|
|
26
26
|
id: string;
|
|
27
27
|
organizationId: string;
|
|
28
28
|
email: string;
|
|
29
|
-
role: "
|
|
30
|
-
status: import('better-auth/
|
|
29
|
+
role: "admin" | "member" | "owner";
|
|
30
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
31
31
|
inviterId: string;
|
|
32
32
|
expiresAt: Date;
|
|
33
33
|
createdAt: Date;
|
|
@@ -35,8 +35,8 @@ export declare function useInviteMember<TAuthClient extends OrganizationAuthClie
|
|
|
35
35
|
id: string;
|
|
36
36
|
organizationId: string;
|
|
37
37
|
email: string;
|
|
38
|
-
role: "
|
|
39
|
-
status: import('better-auth/
|
|
38
|
+
role: "admin" | "member" | "owner";
|
|
39
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
40
40
|
inviterId: string;
|
|
41
41
|
expiresAt: Date;
|
|
42
42
|
createdAt: Date;
|
|
@@ -6,7 +6,7 @@ export type LeaveOrganizationOptions<TAuthClient extends OrganizationAuthClient>
|
|
|
6
6
|
export declare function leaveOrganizationOptions<TAuthClient extends OrganizationAuthClient>(authClient: TAuthClient): import('@tanstack/query-core').WithRequired<import('@tanstack/react-query').UseMutationOptions<Omit<{
|
|
7
7
|
id: string;
|
|
8
8
|
organizationId: string;
|
|
9
|
-
role: "
|
|
9
|
+
role: "admin" | "member" | "owner";
|
|
10
10
|
createdAt: Date;
|
|
11
11
|
userId: string;
|
|
12
12
|
user: {
|
|
@@ -36,7 +36,7 @@ export declare function leaveOrganizationOptions<TAuthClient extends Organizatio
|
|
|
36
36
|
export declare function useLeaveOrganization<TAuthClient extends OrganizationAuthClient>(authClient: TAuthClient, options?: LeaveOrganizationOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseMutationResult<Omit<{
|
|
37
37
|
id: string;
|
|
38
38
|
organizationId: string;
|
|
39
|
-
role: "
|
|
39
|
+
role: "admin" | "member" | "owner";
|
|
40
40
|
createdAt: Date;
|
|
41
41
|
userId: string;
|
|
42
42
|
user: {
|
|
@@ -9,7 +9,7 @@ export declare function rejectInvitationOptions<TAuthClient extends Organization
|
|
|
9
9
|
organizationId: string;
|
|
10
10
|
email: string;
|
|
11
11
|
role: "admin" | "member" | "owner";
|
|
12
|
-
status: import('better-auth/
|
|
12
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
13
13
|
inviterId: string;
|
|
14
14
|
expiresAt: Date;
|
|
15
15
|
createdAt: Date;
|
|
@@ -22,7 +22,7 @@ export declare function useRejectInvitation<TAuthClient extends OrganizationAuth
|
|
|
22
22
|
organizationId: string;
|
|
23
23
|
email: string;
|
|
24
24
|
role: "admin" | "member" | "owner";
|
|
25
|
-
status: import('better-auth/
|
|
25
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
26
26
|
inviterId: string;
|
|
27
27
|
expiresAt: Date;
|
|
28
28
|
createdAt: Date;
|
|
@@ -7,7 +7,7 @@ export declare function removeMemberOptions<TAuthClient extends OrganizationAuth
|
|
|
7
7
|
member: {
|
|
8
8
|
id: string;
|
|
9
9
|
organizationId: string;
|
|
10
|
-
role: "
|
|
10
|
+
role: "admin" | "member" | "owner";
|
|
11
11
|
createdAt: Date;
|
|
12
12
|
userId: string;
|
|
13
13
|
user: {
|
|
@@ -22,7 +22,7 @@ export declare function useRemoveMember<TAuthClient extends OrganizationAuthClie
|
|
|
22
22
|
member: {
|
|
23
23
|
id: string;
|
|
24
24
|
organizationId: string;
|
|
25
|
-
role: "
|
|
25
|
+
role: "admin" | "member" | "owner";
|
|
26
26
|
createdAt: Date;
|
|
27
27
|
userId: string;
|
|
28
28
|
user: {
|
|
@@ -7,7 +7,7 @@ export declare function setActiveOrganizationOptions<TAuthClient extends Organiz
|
|
|
7
7
|
members: {
|
|
8
8
|
id: string;
|
|
9
9
|
organizationId: string;
|
|
10
|
-
role: "
|
|
10
|
+
role: "admin" | "member" | "owner";
|
|
11
11
|
createdAt: Date;
|
|
12
12
|
userId: string;
|
|
13
13
|
user: {
|
|
@@ -21,8 +21,8 @@ export declare function setActiveOrganizationOptions<TAuthClient extends Organiz
|
|
|
21
21
|
id: string;
|
|
22
22
|
organizationId: string;
|
|
23
23
|
email: string;
|
|
24
|
-
role: "
|
|
25
|
-
status: import('better-auth/
|
|
24
|
+
role: "admin" | "member" | "owner";
|
|
25
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
26
26
|
inviterId: string;
|
|
27
27
|
expiresAt: Date;
|
|
28
28
|
createdAt: Date;
|
|
@@ -39,7 +39,7 @@ export declare function useSetActiveOrganization<TAuthClient extends Organizatio
|
|
|
39
39
|
members: {
|
|
40
40
|
id: string;
|
|
41
41
|
organizationId: string;
|
|
42
|
-
role: "
|
|
42
|
+
role: "admin" | "member" | "owner";
|
|
43
43
|
createdAt: Date;
|
|
44
44
|
userId: string;
|
|
45
45
|
user: {
|
|
@@ -53,8 +53,8 @@ export declare function useSetActiveOrganization<TAuthClient extends Organizatio
|
|
|
53
53
|
id: string;
|
|
54
54
|
organizationId: string;
|
|
55
55
|
email: string;
|
|
56
|
-
role: "
|
|
57
|
-
status: import('better-auth/
|
|
56
|
+
role: "admin" | "member" | "owner";
|
|
57
|
+
status: import('better-auth/plugins').InvitationStatus;
|
|
58
58
|
inviterId: string;
|
|
59
59
|
expiresAt: Date;
|
|
60
60
|
createdAt: Date;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { InferData, OAuthProviderAuthClient } from '../../lib/auth-client';
|
|
4
|
+
export type PublicOAuthClientData<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = InferData<TAuthClient["oauth2"]["publicClient"]>;
|
|
5
|
+
export type PublicOAuthClientParams<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = Partial<Omit<NonNullable<Parameters<TAuthClient["oauth2"]["publicClient"]>[0]>, "query">>;
|
|
6
|
+
export type PublicOAuthClientOptions<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = Omit<ReturnType<typeof publicOAuthClientOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
7
|
+
/**
|
|
8
|
+
* Query options factory for an OAuth application's public metadata.
|
|
9
|
+
*
|
|
10
|
+
* @param authClient - The Better Auth client with the OAuth provider plugin.
|
|
11
|
+
* @param clientId - The OAuth client ID from the signed authorization request.
|
|
12
|
+
* @param params - Fetch options forwarded to `oauth2.publicClient`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function publicOAuthClientOptions<TAuthClient extends OAuthProviderAuthClient>(authClient: TAuthClient, clientId: string, params?: PublicOAuthClientParams<TAuthClient>): (import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["oauth2"]["publicClient"]>, BetterFetchError, InferData<TAuthClient["oauth2"]["publicClient"]>, readonly ["auth", "oauthProvider", "publicClient", string | null]>, "queryFn"> & {
|
|
15
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<InferData<TAuthClient["oauth2"]["publicClient"]>, readonly ["auth", "oauthProvider", "publicClient", string | null], never> | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
queryKey: readonly ["auth", "oauthProvider", "publicClient", string | null] & {
|
|
18
|
+
[dataTagSymbol]: InferData<TAuthClient["oauth2"]["publicClient"]>;
|
|
19
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
20
|
+
};
|
|
21
|
+
}) & {
|
|
22
|
+
queryKey: DataTag<readonly ["auth", "oauthProvider", "publicClient", string | null], InferData<TAuthClient["oauth2"]["publicClient"]>, BetterFetchError>;
|
|
23
|
+
};
|
|
24
|
+
export declare const ensurePublicOAuthClient: <TAuthClient extends OAuthProviderAuthClient>(queryClient: QueryClient, authClient: TAuthClient, clientId: string, params?: PublicOAuthClientParams<TAuthClient>) => Promise<InferData<TAuthClient["oauth2"]["publicClient"]>>;
|
|
25
|
+
export declare const prefetchPublicOAuthClient: <TAuthClient extends OAuthProviderAuthClient>(queryClient: QueryClient, authClient: TAuthClient, clientId: string, params?: PublicOAuthClientParams<TAuthClient>) => Promise<void>;
|
|
26
|
+
export declare const fetchPublicOAuthClient: <TAuthClient extends OAuthProviderAuthClient>(queryClient: QueryClient, authClient: TAuthClient, clientId: string, params?: PublicOAuthClientParams<TAuthClient>) => Promise<InferData<TAuthClient["oauth2"]["publicClient"]>>;
|
|
27
|
+
export type UsePublicOAuthClientOptions<TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient> = PublicOAuthClientOptions<TAuthClient> & PublicOAuthClientParams<TAuthClient>;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to an OAuth application's public metadata.
|
|
30
|
+
*
|
|
31
|
+
* The query is disabled until a client ID is available.
|
|
32
|
+
*/
|
|
33
|
+
export declare function usePublicOAuthClient<TAuthClient extends OAuthProviderAuthClient>(authClient: TAuthClient, clientId: string | undefined, options?: UsePublicOAuthClientOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<NoInfer<InferData<TAuthClient["oauth2"]["publicClient"]>>, BetterFetchError>;
|
|
@@ -11,7 +11,7 @@ export declare function listOrganizationMembersOptions<TAuthClient extends Organ
|
|
|
11
11
|
sortDirection?: "asc" | "desc" | undefined;
|
|
12
12
|
filterField?: string | undefined;
|
|
13
13
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
14
|
-
filterOperator?: "in" | "
|
|
14
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
15
15
|
organizationId?: string | undefined;
|
|
16
16
|
organizationSlug?: string | undefined;
|
|
17
17
|
} | null]>, "queryFn"> & {
|
|
@@ -22,7 +22,7 @@ export declare function listOrganizationMembersOptions<TAuthClient extends Organ
|
|
|
22
22
|
sortDirection?: "asc" | "desc" | undefined;
|
|
23
23
|
filterField?: string | undefined;
|
|
24
24
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
25
|
-
filterOperator?: "in" | "
|
|
25
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
26
26
|
organizationId?: string | undefined;
|
|
27
27
|
organizationSlug?: string | undefined;
|
|
28
28
|
} | null], never> | undefined;
|
|
@@ -34,7 +34,7 @@ export declare function listOrganizationMembersOptions<TAuthClient extends Organ
|
|
|
34
34
|
sortDirection?: "asc" | "desc" | undefined;
|
|
35
35
|
filterField?: string | undefined;
|
|
36
36
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
37
|
-
filterOperator?: "in" | "
|
|
37
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
38
38
|
organizationId?: string | undefined;
|
|
39
39
|
organizationSlug?: string | undefined;
|
|
40
40
|
} | null] & {
|
|
@@ -49,7 +49,7 @@ export declare function listOrganizationMembersOptions<TAuthClient extends Organ
|
|
|
49
49
|
sortDirection?: "asc" | "desc" | undefined;
|
|
50
50
|
filterField?: string | undefined;
|
|
51
51
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
52
|
-
filterOperator?: "in" | "
|
|
52
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
53
53
|
organizationId?: string | undefined;
|
|
54
54
|
organizationSlug?: string | undefined;
|
|
55
55
|
} | null], InferData<TAuthClient["organization"]["listMembers"]>, BetterFetchError>;
|
|
@@ -18,7 +18,7 @@ export declare function listOrganizationMembersOptions<TAuth extends Organizatio
|
|
|
18
18
|
sortDirection?: "asc" | "desc" | undefined;
|
|
19
19
|
filterField?: string | undefined;
|
|
20
20
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
21
|
-
filterOperator?: "in" | "
|
|
21
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
22
22
|
organizationId?: string | undefined;
|
|
23
23
|
organizationSlug?: string | undefined;
|
|
24
24
|
} | null]>, "queryFn"> & {
|
|
@@ -29,7 +29,7 @@ export declare function listOrganizationMembersOptions<TAuth extends Organizatio
|
|
|
29
29
|
sortDirection?: "asc" | "desc" | undefined;
|
|
30
30
|
filterField?: string | undefined;
|
|
31
31
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
32
|
-
filterOperator?: "in" | "
|
|
32
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
33
33
|
organizationId?: string | undefined;
|
|
34
34
|
organizationSlug?: string | undefined;
|
|
35
35
|
} | null], never> | undefined;
|
|
@@ -41,7 +41,7 @@ export declare function listOrganizationMembersOptions<TAuth extends Organizatio
|
|
|
41
41
|
sortDirection?: "asc" | "desc" | undefined;
|
|
42
42
|
filterField?: string | undefined;
|
|
43
43
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
44
|
-
filterOperator?: "in" | "
|
|
44
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
45
45
|
organizationId?: string | undefined;
|
|
46
46
|
organizationSlug?: string | undefined;
|
|
47
47
|
} | null] & {
|
|
@@ -56,7 +56,7 @@ export declare function listOrganizationMembersOptions<TAuth extends Organizatio
|
|
|
56
56
|
sortDirection?: "asc" | "desc" | undefined;
|
|
57
57
|
filterField?: string | undefined;
|
|
58
58
|
filterValue?: string | number | boolean | string[] | number[] | undefined;
|
|
59
|
-
filterOperator?: "in" | "
|
|
59
|
+
filterOperator?: "in" | "contains" | "starts_with" | "ends_with" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not_in" | undefined;
|
|
60
60
|
organizationId?: string | undefined;
|
|
61
61
|
organizationSlug?: string | undefined;
|
|
62
62
|
} | null], Awaited<ReturnType<TAuth["api"]["listMembers"]>>, APIError>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth-ui/react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@better-auth/api-key": "^1.6.19",
|
|
40
|
+
"@better-auth/oauth-provider": "1.6.19",
|
|
40
41
|
"@better-auth/passkey": "^1.6.19",
|
|
41
42
|
"@react-email/ui": "6.6.8",
|
|
42
43
|
"@tanstack/query-core": "^5.100.14",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"@better-auth-ui/core": "*",
|
|
62
63
|
"@better-auth/api-key": ">=1.6.19",
|
|
64
|
+
"@better-auth/oauth-provider": ">=1.6.19",
|
|
63
65
|
"@better-auth/passkey": ">=1.6.19",
|
|
64
66
|
"@tanstack/query-core": ">=5.100.14",
|
|
65
67
|
"@tanstack/react-query": ">=5.100.14",
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type * from "./lib/auth-client"
|
|
|
14
14
|
export * from "./lib/auth-plugin"
|
|
15
15
|
export * from "./lib/provider-icons"
|
|
16
16
|
export * from "./lib/settings-tab"
|
|
17
|
+
export * from "./mutations/admin/stop-impersonating-mutation"
|
|
17
18
|
export * from "./mutations/api-key/create-api-key-mutation"
|
|
18
19
|
export * from "./mutations/api-key/delete-api-key-mutation"
|
|
19
20
|
export * from "./mutations/auth/request-password-reset-mutation"
|
|
@@ -30,6 +31,7 @@ export * from "./mutations/device-authorization/verify-device-code-mutation"
|
|
|
30
31
|
export * from "./mutations/magic-link/sign-in-magic-link-mutation"
|
|
31
32
|
export * from "./mutations/multi-session/revoke-multi-session-mutation"
|
|
32
33
|
export * from "./mutations/multi-session/set-active-session-mutation"
|
|
34
|
+
export * from "./mutations/oauth-provider/oauth-consent-mutation"
|
|
33
35
|
export * from "./mutations/organization"
|
|
34
36
|
export * from "./mutations/passkey/add-passkey-mutation"
|
|
35
37
|
export * from "./mutations/passkey/delete-passkey-mutation"
|
|
@@ -47,6 +49,7 @@ export * from "./queries/api-key/list-api-keys-query"
|
|
|
47
49
|
export * from "./queries/auth/session-query"
|
|
48
50
|
export * from "./queries/auth-query-options"
|
|
49
51
|
export * from "./queries/multi-session/list-device-sessions-query"
|
|
52
|
+
export * from "./queries/oauth-provider/public-oauth-client-query"
|
|
50
53
|
export * from "./queries/organization"
|
|
51
54
|
export * from "./queries/passkey/list-passkeys-query"
|
|
52
55
|
export * from "./queries/settings/account-info-query"
|
package/src/lib/auth-client.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { apiKeyClient } from "@better-auth/api-key/client"
|
|
2
|
+
import type { oauthProviderClient } from "@better-auth/oauth-provider/client"
|
|
2
3
|
import type { passkeyClient } from "@better-auth/passkey/client"
|
|
3
4
|
import type {
|
|
5
|
+
AdminClientOptions,
|
|
6
|
+
adminClient,
|
|
4
7
|
deviceAuthorizationClient,
|
|
5
8
|
lastLoginMethodClient,
|
|
6
9
|
magicLinkClient,
|
|
@@ -18,6 +21,12 @@ export type AuthClient = ReturnType<typeof createAuthClient>
|
|
|
18
21
|
// Turbopack, older configs, etc.) and keeps the plugin packages out of
|
|
19
22
|
// consumers' runtime bundles entirely.
|
|
20
23
|
|
|
24
|
+
export type AdminAuthClient = ReturnType<
|
|
25
|
+
typeof createAuthClient<{
|
|
26
|
+
plugins: [ReturnType<typeof adminClient<AdminClientOptions>>]
|
|
27
|
+
}>
|
|
28
|
+
>
|
|
29
|
+
|
|
21
30
|
export type MagicLinkAuthClient = ReturnType<
|
|
22
31
|
typeof createAuthClient<{ plugins: [ReturnType<typeof magicLinkClient>] }>
|
|
23
32
|
>
|
|
@@ -46,6 +55,12 @@ export type ApiKeyAuthClient = ReturnType<
|
|
|
46
55
|
typeof createAuthClient<{ plugins: [ReturnType<typeof apiKeyClient>] }>
|
|
47
56
|
>
|
|
48
57
|
|
|
58
|
+
export type OAuthProviderAuthClient = ReturnType<
|
|
59
|
+
typeof createAuthClient<{
|
|
60
|
+
plugins: [ReturnType<typeof oauthProviderClient>]
|
|
61
|
+
}>
|
|
62
|
+
>
|
|
63
|
+
|
|
49
64
|
export type UsernameAuthClient = ReturnType<
|
|
50
65
|
typeof createAuthClient<{ plugins: [ReturnType<typeof usernameClient>] }>
|
|
51
66
|
>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { adminMutationKeys } from "@better-auth-ui/core/plugins"
|
|
3
|
+
import {
|
|
4
|
+
mutationOptions,
|
|
5
|
+
type QueryClient,
|
|
6
|
+
useMutation
|
|
7
|
+
} from "@tanstack/react-query"
|
|
8
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
9
|
+
|
|
10
|
+
import type { AdminAuthClient } from "../../lib/auth-client"
|
|
11
|
+
|
|
12
|
+
export type StopImpersonatingParams<TAuthClient extends AdminAuthClient> =
|
|
13
|
+
Parameters<TAuthClient["admin"]["stopImpersonating"]>[0]
|
|
14
|
+
|
|
15
|
+
export type StopImpersonatingOptions<TAuthClient extends AdminAuthClient> =
|
|
16
|
+
Omit<
|
|
17
|
+
ReturnType<typeof stopImpersonatingOptions<TAuthClient>>,
|
|
18
|
+
"mutationKey" | "mutationFn" | "meta"
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Mutation options factory for restoring the administrator's session.
|
|
23
|
+
*
|
|
24
|
+
* @param authClient - The Better Auth client with the admin plugin.
|
|
25
|
+
*/
|
|
26
|
+
export function stopImpersonatingOptions<TAuthClient extends AdminAuthClient>(
|
|
27
|
+
authClient: TAuthClient
|
|
28
|
+
) {
|
|
29
|
+
const mutationKey = adminMutationKeys.stopImpersonating
|
|
30
|
+
|
|
31
|
+
const mutationFn = (params?: StopImpersonatingParams<TAuthClient>) =>
|
|
32
|
+
authClient.admin.stopImpersonating({
|
|
33
|
+
...(params ?? {}),
|
|
34
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return mutationOptions<
|
|
38
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
39
|
+
BetterFetchError,
|
|
40
|
+
Parameters<typeof mutationFn>[0]
|
|
41
|
+
>({
|
|
42
|
+
mutationKey,
|
|
43
|
+
mutationFn
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Stop impersonating a user and restore the administrator's session.
|
|
49
|
+
*
|
|
50
|
+
* On success, `MutationInvalidator` awaits invalidation of the session query
|
|
51
|
+
* so every auth surface immediately reflects the restored administrator.
|
|
52
|
+
*
|
|
53
|
+
* @param authClient - The Better Auth client with the admin plugin.
|
|
54
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
55
|
+
*/
|
|
56
|
+
export function useStopImpersonating<TAuthClient extends AdminAuthClient>(
|
|
57
|
+
authClient: TAuthClient,
|
|
58
|
+
options?: StopImpersonatingOptions<TAuthClient>,
|
|
59
|
+
queryClient?: QueryClient
|
|
60
|
+
) {
|
|
61
|
+
return useMutation(
|
|
62
|
+
{
|
|
63
|
+
...stopImpersonatingOptions(authClient),
|
|
64
|
+
...options,
|
|
65
|
+
meta: {
|
|
66
|
+
awaits: [authQueryKeys.session]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
queryClient
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { oauthProviderMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
|
|
4
|
+
import type { OAuthProviderAuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
6
|
+
|
|
7
|
+
export type OAuthConsentParams<
|
|
8
|
+
TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient
|
|
9
|
+
> = Parameters<TAuthClient["oauth2"]["consent"]>[0]
|
|
10
|
+
|
|
11
|
+
export type OAuthConsentOptions<
|
|
12
|
+
TAuthClient extends OAuthProviderAuthClient = OAuthProviderAuthClient
|
|
13
|
+
> = Omit<
|
|
14
|
+
ReturnType<typeof oauthConsentOptions<TAuthClient>>,
|
|
15
|
+
"mutationKey" | "mutationFn"
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mutation options factory for accepting or denying an OAuth request.
|
|
20
|
+
*
|
|
21
|
+
* Better Auth reads the signed authorization query from the current URL and
|
|
22
|
+
* validates the resulting redirect.
|
|
23
|
+
*/
|
|
24
|
+
export function oauthConsentOptions<
|
|
25
|
+
TAuthClient extends OAuthProviderAuthClient
|
|
26
|
+
>(authClient: TAuthClient) {
|
|
27
|
+
return authMutationOptions(
|
|
28
|
+
authClient.oauth2.consent,
|
|
29
|
+
oauthProviderMutationKeys.consent
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useOAuthConsent<TAuthClient extends OAuthProviderAuthClient>(
|
|
34
|
+
authClient: TAuthClient,
|
|
35
|
+
options?: OAuthConsentOptions<TAuthClient>
|
|
36
|
+
) {
|
|
37
|
+
return useMutation({
|
|
38
|
+
...oauthConsentOptions(authClient),
|
|
39
|
+
...options
|
|
40
|
+
})
|
|
41
|
+
}
|