@better-auth-ui/react 1.6.30 → 1.6.31
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 +334 -301
- package/dist/lib/auth-client.d.ts +4 -1
- package/dist/mutations/device-authorization/approve-device-mutation.d.ts +33 -0
- package/dist/mutations/device-authorization/deny-device-mutation.d.ts +33 -0
- package/dist/mutations/device-authorization/verify-device-code-mutation.d.ts +107 -0
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/lib/auth-client.ts +7 -0
- package/src/mutations/device-authorization/approve-device-mutation.ts +45 -0
- package/src/mutations/device-authorization/deny-device-mutation.ts +45 -0
- package/src/mutations/device-authorization/verify-device-code-mutation.ts +48 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { apiKeyClient } from '@better-auth/api-key/client';
|
|
2
2
|
import { passkeyClient } from '@better-auth/passkey/client';
|
|
3
|
-
import { lastLoginMethodClient, magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
|
|
3
|
+
import { deviceAuthorizationClient, lastLoginMethodClient, magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
|
|
4
4
|
import { createAuthClient } from 'better-auth/react';
|
|
5
5
|
export type AuthClient = ReturnType<typeof createAuthClient>;
|
|
6
6
|
export type MagicLinkAuthClient = ReturnType<typeof createAuthClient<{
|
|
7
7
|
plugins: [ReturnType<typeof magicLinkClient>];
|
|
8
8
|
}>>;
|
|
9
|
+
export type DeviceAuthorizationAuthClient = ReturnType<typeof createAuthClient<{
|
|
10
|
+
plugins: [ReturnType<typeof deviceAuthorizationClient>];
|
|
11
|
+
}>>;
|
|
9
12
|
export type LastLoginMethodAuthClient = ReturnType<typeof createAuthClient<{
|
|
10
13
|
plugins: [ReturnType<typeof lastLoginMethodClient>];
|
|
11
14
|
}>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DeviceAuthorizationAuthClient } from '../../lib/auth-client';
|
|
2
|
+
export type ApproveDeviceParams<TAuthClient extends DeviceAuthorizationAuthClient> = Parameters<TAuthClient["device"]["approve"]>[0];
|
|
3
|
+
export type ApproveDeviceOptions<TAuthClient extends DeviceAuthorizationAuthClient> = Omit<ReturnType<typeof approveDeviceOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for approving a pending device request.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
8
|
+
*/
|
|
9
|
+
export declare function approveDeviceOptions<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient): import('../auth-mutation-options').AuthMutationOptions<(<FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
10
|
+
userCode: string;
|
|
11
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
12
|
+
userCode: string;
|
|
13
|
+
} & {
|
|
14
|
+
fetchOptions?: FetchOptions | undefined;
|
|
15
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}, {
|
|
18
|
+
error: "invalid_request" | "expired_token" | "access_denied" | "device_code_already_processed" | "unauthorized";
|
|
19
|
+
error_description: string;
|
|
20
|
+
}, FetchOptions["throw"] extends true ? true : false>>), readonly ["auth", "deviceAuthorization", "approve"]>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a mutation for approving a pending device request.
|
|
23
|
+
*
|
|
24
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
25
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useApproveDevice<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient, options?: ApproveDeviceOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<any, import('better-auth/client').BetterFetchError, import('better-auth').Prettify<{
|
|
28
|
+
userCode: string;
|
|
29
|
+
} & {
|
|
30
|
+
fetchOptions?: import('better-auth').ClientFetchOption<Partial<{
|
|
31
|
+
userCode: string;
|
|
32
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined> | undefined;
|
|
33
|
+
}>, unknown>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DeviceAuthorizationAuthClient } from '../../lib/auth-client';
|
|
2
|
+
export type DenyDeviceParams<TAuthClient extends DeviceAuthorizationAuthClient> = Parameters<TAuthClient["device"]["deny"]>[0];
|
|
3
|
+
export type DenyDeviceOptions<TAuthClient extends DeviceAuthorizationAuthClient> = Omit<ReturnType<typeof denyDeviceOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for denying a pending device request.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
8
|
+
*/
|
|
9
|
+
export declare function denyDeviceOptions<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient): import('../auth-mutation-options').AuthMutationOptions<(<FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
10
|
+
userCode: string;
|
|
11
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
12
|
+
userCode: string;
|
|
13
|
+
} & {
|
|
14
|
+
fetchOptions?: FetchOptions | undefined;
|
|
15
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}, {
|
|
18
|
+
error: "invalid_request" | "expired_token" | "access_denied" | "unauthorized";
|
|
19
|
+
error_description: string;
|
|
20
|
+
}, FetchOptions["throw"] extends true ? true : false>>), readonly ["auth", "deviceAuthorization", "deny"]>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a mutation for denying a pending device request.
|
|
23
|
+
*
|
|
24
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
25
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useDenyDevice<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient, options?: DenyDeviceOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<any, import('better-auth/client').BetterFetchError, import('better-auth').Prettify<{
|
|
28
|
+
userCode: string;
|
|
29
|
+
} & {
|
|
30
|
+
fetchOptions?: import('better-auth').ClientFetchOption<Partial<{
|
|
31
|
+
userCode: string;
|
|
32
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined> | undefined;
|
|
33
|
+
}>, unknown>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { DeviceAuthorizationAuthClient } from '../../lib/auth-client';
|
|
2
|
+
export type VerifyDeviceCodeParams<TAuthClient extends DeviceAuthorizationAuthClient> = Parameters<TAuthClient["device"]>[0];
|
|
3
|
+
export type VerifyDeviceCodeOptions<TAuthClient extends DeviceAuthorizationAuthClient> = Omit<ReturnType<typeof verifyDeviceCodeOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for verifying and claiming a device user code.
|
|
6
|
+
*
|
|
7
|
+
* The Better Auth endpoint uses GET, but this operation is modeled as a
|
|
8
|
+
* mutation because verification binds the code to the current session.
|
|
9
|
+
*
|
|
10
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
11
|
+
*/
|
|
12
|
+
export declare function verifyDeviceCodeOptions<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient): import('../auth-mutation-options').AuthMutationOptions<{
|
|
13
|
+
code: <FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
14
|
+
client_id: string;
|
|
15
|
+
user_id?: string | undefined;
|
|
16
|
+
scope?: string | undefined;
|
|
17
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
18
|
+
client_id: string;
|
|
19
|
+
user_id?: string | undefined;
|
|
20
|
+
scope?: string | undefined;
|
|
21
|
+
} & {
|
|
22
|
+
fetchOptions?: FetchOptions | undefined;
|
|
23
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
24
|
+
device_code: string;
|
|
25
|
+
user_code: string;
|
|
26
|
+
verification_uri: string;
|
|
27
|
+
verification_uri_complete: string;
|
|
28
|
+
expires_in: number;
|
|
29
|
+
interval: number;
|
|
30
|
+
}, {
|
|
31
|
+
error: "invalid_request" | "invalid_client";
|
|
32
|
+
error_description: string;
|
|
33
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
34
|
+
} & {
|
|
35
|
+
token: <FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
36
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code";
|
|
37
|
+
device_code: string;
|
|
38
|
+
client_id: string;
|
|
39
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
40
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code";
|
|
41
|
+
device_code: string;
|
|
42
|
+
client_id: string;
|
|
43
|
+
} & {
|
|
44
|
+
fetchOptions?: FetchOptions | undefined;
|
|
45
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
46
|
+
access_token: string;
|
|
47
|
+
token_type: string;
|
|
48
|
+
expires_in: number;
|
|
49
|
+
scope: string;
|
|
50
|
+
}, {
|
|
51
|
+
error: "invalid_request" | "authorization_pending" | "slow_down" | "expired_token" | "access_denied" | "invalid_grant";
|
|
52
|
+
error_description: string;
|
|
53
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
54
|
+
} & (<FetchOptions extends import('better-auth').ClientFetchOption<never, Partial<{
|
|
55
|
+
user_code: string;
|
|
56
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
57
|
+
query: {
|
|
58
|
+
user_code: string;
|
|
59
|
+
};
|
|
60
|
+
fetchOptions?: FetchOptions | undefined;
|
|
61
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
62
|
+
user_code: string;
|
|
63
|
+
status: string;
|
|
64
|
+
}, {
|
|
65
|
+
error: "invalid_request";
|
|
66
|
+
error_description: string;
|
|
67
|
+
}, FetchOptions["throw"] extends true ? true : false>>) & {
|
|
68
|
+
approve: <FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
69
|
+
userCode: string;
|
|
70
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
71
|
+
userCode: string;
|
|
72
|
+
} & {
|
|
73
|
+
fetchOptions?: FetchOptions | undefined;
|
|
74
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
75
|
+
success: boolean;
|
|
76
|
+
}, {
|
|
77
|
+
error: "invalid_request" | "expired_token" | "access_denied" | "device_code_already_processed" | "unauthorized";
|
|
78
|
+
error_description: string;
|
|
79
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
80
|
+
} & {
|
|
81
|
+
deny: <FetchOptions extends import('better-auth').ClientFetchOption<Partial<{
|
|
82
|
+
userCode: string;
|
|
83
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import('better-auth').Prettify<{
|
|
84
|
+
userCode: string;
|
|
85
|
+
} & {
|
|
86
|
+
fetchOptions?: FetchOptions | undefined;
|
|
87
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import('better-auth/client').BetterFetchResponse<{
|
|
88
|
+
success: boolean;
|
|
89
|
+
}, {
|
|
90
|
+
error: "invalid_request" | "expired_token" | "access_denied" | "unauthorized";
|
|
91
|
+
error_description: string;
|
|
92
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
93
|
+
}, readonly ["auth", "deviceAuthorization", "verify"]>;
|
|
94
|
+
/**
|
|
95
|
+
* Create a mutation for verifying and claiming a device user code.
|
|
96
|
+
*
|
|
97
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
98
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function useVerifyDeviceCode<TAuthClient extends DeviceAuthorizationAuthClient>(authClient: TAuthClient, options?: VerifyDeviceCodeOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<any, import('better-auth/client').BetterFetchError, import('better-auth').Prettify<{
|
|
101
|
+
query: {
|
|
102
|
+
user_code: string;
|
|
103
|
+
};
|
|
104
|
+
fetchOptions?: import('better-auth').ClientFetchOption<never, Partial<{
|
|
105
|
+
user_code: string;
|
|
106
|
+
}> & Record<string, any>, Record<string, any> | undefined> | undefined;
|
|
107
|
+
}>, unknown>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -24,6 +24,9 @@ export * from "./mutations/auth/sign-in-social-mutation"
|
|
|
24
24
|
export * from "./mutations/auth/sign-out-mutation"
|
|
25
25
|
export * from "./mutations/auth/sign-up-email-mutation"
|
|
26
26
|
export * from "./mutations/auth-mutation-options"
|
|
27
|
+
export * from "./mutations/device-authorization/approve-device-mutation"
|
|
28
|
+
export * from "./mutations/device-authorization/deny-device-mutation"
|
|
29
|
+
export * from "./mutations/device-authorization/verify-device-code-mutation"
|
|
27
30
|
export * from "./mutations/magic-link/sign-in-magic-link-mutation"
|
|
28
31
|
export * from "./mutations/multi-session/revoke-multi-session-mutation"
|
|
29
32
|
export * from "./mutations/multi-session/set-active-session-mutation"
|
package/src/lib/auth-client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { apiKeyClient } from "@better-auth/api-key/client"
|
|
2
2
|
import type { passkeyClient } from "@better-auth/passkey/client"
|
|
3
3
|
import type {
|
|
4
|
+
deviceAuthorizationClient,
|
|
4
5
|
lastLoginMethodClient,
|
|
5
6
|
magicLinkClient,
|
|
6
7
|
multiSessionClient,
|
|
@@ -21,6 +22,12 @@ export type MagicLinkAuthClient = ReturnType<
|
|
|
21
22
|
typeof createAuthClient<{ plugins: [ReturnType<typeof magicLinkClient>] }>
|
|
22
23
|
>
|
|
23
24
|
|
|
25
|
+
export type DeviceAuthorizationAuthClient = ReturnType<
|
|
26
|
+
typeof createAuthClient<{
|
|
27
|
+
plugins: [ReturnType<typeof deviceAuthorizationClient>]
|
|
28
|
+
}>
|
|
29
|
+
>
|
|
30
|
+
|
|
24
31
|
export type LastLoginMethodAuthClient = ReturnType<
|
|
25
32
|
typeof createAuthClient<{
|
|
26
33
|
plugins: [ReturnType<typeof lastLoginMethodClient>]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { deviceAuthorizationMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
|
|
4
|
+
import type { DeviceAuthorizationAuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
6
|
+
|
|
7
|
+
export type ApproveDeviceParams<
|
|
8
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
9
|
+
> = Parameters<TAuthClient["device"]["approve"]>[0]
|
|
10
|
+
|
|
11
|
+
export type ApproveDeviceOptions<
|
|
12
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
13
|
+
> = Omit<
|
|
14
|
+
ReturnType<typeof approveDeviceOptions<TAuthClient>>,
|
|
15
|
+
"mutationKey" | "mutationFn"
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mutation options factory for approving a pending device request.
|
|
20
|
+
*
|
|
21
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
22
|
+
*/
|
|
23
|
+
export function approveDeviceOptions<
|
|
24
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
25
|
+
>(authClient: TAuthClient) {
|
|
26
|
+
return authMutationOptions(
|
|
27
|
+
authClient.device.approve,
|
|
28
|
+
deviceAuthorizationMutationKeys.approve
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a mutation for approving a pending device request.
|
|
34
|
+
*
|
|
35
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
36
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
37
|
+
*/
|
|
38
|
+
export function useApproveDevice<
|
|
39
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
40
|
+
>(authClient: TAuthClient, options?: ApproveDeviceOptions<TAuthClient>) {
|
|
41
|
+
return useMutation({
|
|
42
|
+
...approveDeviceOptions(authClient),
|
|
43
|
+
...options
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { deviceAuthorizationMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
|
|
4
|
+
import type { DeviceAuthorizationAuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
6
|
+
|
|
7
|
+
export type DenyDeviceParams<
|
|
8
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
9
|
+
> = Parameters<TAuthClient["device"]["deny"]>[0]
|
|
10
|
+
|
|
11
|
+
export type DenyDeviceOptions<
|
|
12
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
13
|
+
> = Omit<
|
|
14
|
+
ReturnType<typeof denyDeviceOptions<TAuthClient>>,
|
|
15
|
+
"mutationKey" | "mutationFn"
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mutation options factory for denying a pending device request.
|
|
20
|
+
*
|
|
21
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
22
|
+
*/
|
|
23
|
+
export function denyDeviceOptions<
|
|
24
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
25
|
+
>(authClient: TAuthClient) {
|
|
26
|
+
return authMutationOptions(
|
|
27
|
+
authClient.device.deny,
|
|
28
|
+
deviceAuthorizationMutationKeys.deny
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a mutation for denying a pending device request.
|
|
34
|
+
*
|
|
35
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
36
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
37
|
+
*/
|
|
38
|
+
export function useDenyDevice<
|
|
39
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
40
|
+
>(authClient: TAuthClient, options?: DenyDeviceOptions<TAuthClient>) {
|
|
41
|
+
return useMutation({
|
|
42
|
+
...denyDeviceOptions(authClient),
|
|
43
|
+
...options
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { deviceAuthorizationMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
|
|
4
|
+
import type { DeviceAuthorizationAuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
6
|
+
|
|
7
|
+
export type VerifyDeviceCodeParams<
|
|
8
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
9
|
+
> = Parameters<TAuthClient["device"]>[0]
|
|
10
|
+
|
|
11
|
+
export type VerifyDeviceCodeOptions<
|
|
12
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
13
|
+
> = Omit<
|
|
14
|
+
ReturnType<typeof verifyDeviceCodeOptions<TAuthClient>>,
|
|
15
|
+
"mutationKey" | "mutationFn"
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mutation options factory for verifying and claiming a device user code.
|
|
20
|
+
*
|
|
21
|
+
* The Better Auth endpoint uses GET, but this operation is modeled as a
|
|
22
|
+
* mutation because verification binds the code to the current session.
|
|
23
|
+
*
|
|
24
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
25
|
+
*/
|
|
26
|
+
export function verifyDeviceCodeOptions<
|
|
27
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
28
|
+
>(authClient: TAuthClient) {
|
|
29
|
+
return authMutationOptions(
|
|
30
|
+
authClient.device,
|
|
31
|
+
deviceAuthorizationMutationKeys.verify
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a mutation for verifying and claiming a device user code.
|
|
37
|
+
*
|
|
38
|
+
* @param authClient - The Better Auth client with the device-authorization plugin.
|
|
39
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
40
|
+
*/
|
|
41
|
+
export function useVerifyDeviceCode<
|
|
42
|
+
TAuthClient extends DeviceAuthorizationAuthClient
|
|
43
|
+
>(authClient: TAuthClient, options?: VerifyDeviceCodeOptions<TAuthClient>) {
|
|
44
|
+
return useMutation({
|
|
45
|
+
...verifyDeviceCodeOptions(authClient),
|
|
46
|
+
...options
|
|
47
|
+
})
|
|
48
|
+
}
|