@imtf/auth 0.0.1-alpha.1 → 0.0.1-alpha.2
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/lib/hooks/useSignOut.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
function useSignOut({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
postSignOutRedirectPath = "/auth/sign-in?sign-out=success",
|
|
5
|
+
retrieveSignOutUrlPath = "/api/auth/sign-out-url",
|
|
6
|
+
onSignOutSuccess,
|
|
7
7
|
authClient,
|
|
8
8
|
origin = window.location.origin
|
|
9
9
|
}) {
|
|
10
10
|
const standardSignOut = useCallback(() => {
|
|
11
11
|
void authClient.signOut({
|
|
12
12
|
fetchOptions: {
|
|
13
|
-
onSuccess:
|
|
13
|
+
onSuccess: onSignOutSuccess
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
}, [authClient,
|
|
16
|
+
}, [authClient, onSignOutSuccess]);
|
|
17
17
|
const handleSignOut = useCallback(async () => {
|
|
18
|
-
const postLogoutRedirectUri = `${origin}${
|
|
18
|
+
const postLogoutRedirectUri = `${origin}${postSignOutRedirectPath}`;
|
|
19
19
|
try {
|
|
20
20
|
const response = await fetch(
|
|
21
|
-
`${
|
|
21
|
+
`${retrieveSignOutUrlPath}?post_logout_redirect_uri=${encodeURIComponent(postLogoutRedirectUri)}`
|
|
22
22
|
);
|
|
23
23
|
if (!response.ok) {
|
|
24
24
|
const { error } = await response.json().catch(() => ({ error: null }));
|
|
@@ -41,8 +41,8 @@ function useSignOut({
|
|
|
41
41
|
}, [
|
|
42
42
|
authClient,
|
|
43
43
|
origin,
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
postSignOutRedirectPath,
|
|
45
|
+
retrieveSignOutUrlPath,
|
|
46
46
|
standardSignOut
|
|
47
47
|
]);
|
|
48
48
|
return { handleSignOut };
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { getBetterAuthClientOptions } from "../index";
|
|
1
|
+
import type { createAuthClient } from "better-auth/react";
|
|
3
2
|
/**
|
|
4
3
|
* Custom hook for handling user sign-out with support for federated logout.
|
|
5
4
|
*
|
|
6
5
|
* @param params - Configuration options
|
|
7
|
-
* @param params.
|
|
6
|
+
* @param params.postSignOutRedirectPath - Path to redirect to after logout (defaults to "/auth/sign-in")
|
|
8
7
|
* @returns Object containing handleSignOut function to initiate the logout process
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```tsx
|
|
12
|
-
* const { handleSignOut } = useSignOut({
|
|
11
|
+
* const { handleSignOut } = useSignOut({ postSignOutRedirectPath: "/auth/sign-in" });
|
|
13
12
|
* ```
|
|
14
13
|
*/
|
|
15
|
-
export declare function useSignOut({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
authClient:
|
|
14
|
+
export declare function useSignOut({ postSignOutRedirectPath, retrieveSignOutUrlPath, onSignOutSuccess, authClient, origin, }: {
|
|
15
|
+
postSignOutRedirectPath?: string;
|
|
16
|
+
retrieveSignOutUrlPath?: string;
|
|
17
|
+
onSignOutSuccess?: () => void;
|
|
18
|
+
authClient: ReturnType<typeof createAuthClient>;
|
|
20
19
|
origin?: string;
|
|
21
20
|
}): {
|
|
22
21
|
handleSignOut: () => Promise<void>;
|