@imtf/auth 1.0.1-beta.0 → 1.0.1-beta.3
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.
|
@@ -2,18 +2,20 @@ import { useCallback } from "react";
|
|
|
2
2
|
function useSignOut({
|
|
3
3
|
postSignOutRedirectPath = "/auth/sign-in?sign-out=success",
|
|
4
4
|
retrieveSignOutUrlPath = "/api/auth/sign-out-url",
|
|
5
|
+
onSignOutStart,
|
|
5
6
|
onSignOutSuccess,
|
|
6
7
|
authClient,
|
|
7
8
|
origin: providedOrigin
|
|
8
9
|
}) {
|
|
9
10
|
const origin = providedOrigin ?? (typeof window !== "undefined" ? window.location.origin : "");
|
|
10
11
|
const standardSignOut = useCallback(() => {
|
|
12
|
+
onSignOutStart?.();
|
|
11
13
|
void authClient.signOut({
|
|
12
14
|
fetchOptions: {
|
|
13
15
|
onSuccess: onSignOutSuccess
|
|
14
16
|
}
|
|
15
17
|
});
|
|
16
|
-
}, [authClient, onSignOutSuccess]);
|
|
18
|
+
}, [authClient, onSignOutStart, onSignOutSuccess]);
|
|
17
19
|
const handleSignOut = useCallback(async () => {
|
|
18
20
|
const postLogoutRedirectUri = `${origin}${postSignOutRedirectPath}`;
|
|
19
21
|
try {
|
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
import type { createAuthClient } from "better-auth/react";
|
|
2
|
+
export type UseSignOutOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Path to redirect to after sign-out. Defaults to "/auth/sign-in?sign-out=success".
|
|
5
|
+
*/
|
|
6
|
+
postSignOutRedirectPath?: string;
|
|
7
|
+
/**
|
|
8
|
+
* API endpoint to retrieve the federated logout URL. Defaults to "/api/auth/sign-out-url".
|
|
9
|
+
*/
|
|
10
|
+
retrieveSignOutUrlPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional callback to execute before starting the sign-out process.
|
|
13
|
+
*/
|
|
14
|
+
onSignOutStart?: () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Optional callback to execute after a successful sign-out.
|
|
17
|
+
*/
|
|
18
|
+
onSignOutSuccess?: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Auth client instance created by better-auth. This is required to perform the sign-out operation.
|
|
21
|
+
*/
|
|
22
|
+
authClient: ReturnType<typeof createAuthClient>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional origin to use for constructing the post-logout redirect URI. Defaults to the current window location origin.
|
|
25
|
+
*/
|
|
26
|
+
origin?: string;
|
|
27
|
+
};
|
|
2
28
|
/**
|
|
3
29
|
* Custom hook for handling user sign-out with support for federated logout.
|
|
4
30
|
*
|
|
5
|
-
* @param params - Configuration options
|
|
6
|
-
* @param params.postSignOutRedirectPath - Path to redirect to after sign-out (defaults to "/auth/sign-in?sign-out=success")
|
|
7
|
-
* @returns Object containing handleSignOut function to initiate the sign-out process
|
|
8
|
-
*
|
|
9
31
|
* @example
|
|
10
32
|
* ```tsx
|
|
11
33
|
* const { handleSignOut } = useSignOut({ postSignOutRedirectPath: "/auth/sign-in?sign-out=success" });
|
|
12
34
|
* ```
|
|
13
35
|
*/
|
|
14
|
-
export declare function useSignOut({ postSignOutRedirectPath, retrieveSignOutUrlPath, onSignOutSuccess, authClient, origin: providedOrigin, }: {
|
|
15
|
-
postSignOutRedirectPath?: string;
|
|
16
|
-
retrieveSignOutUrlPath?: string;
|
|
17
|
-
onSignOutSuccess?: () => void;
|
|
18
|
-
authClient: ReturnType<typeof createAuthClient>;
|
|
19
|
-
origin?: string;
|
|
20
|
-
}): {
|
|
36
|
+
export declare function useSignOut({ postSignOutRedirectPath, retrieveSignOutUrlPath, onSignOutStart, onSignOutSuccess, authClient, origin: providedOrigin, }: UseSignOutOptions): {
|
|
21
37
|
handleSignOut: () => Promise<void>;
|
|
22
38
|
};
|
|
@@ -57,6 +57,7 @@ export declare function getBetterAuthClientOptions(): {
|
|
|
57
57
|
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
58
58
|
error_description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
59
59
|
state: import("zod").ZodOptional<import("zod").ZodString>;
|
|
60
|
+
iss: import("zod").ZodOptional<import("zod").ZodString>;
|
|
60
61
|
}, import("better-auth").$strip>;
|
|
61
62
|
metadata: {
|
|
62
63
|
allowedMediaTypes: string[];
|
|
@@ -151,13 +152,25 @@ export declare function getBetterAuthClientOptions(): {
|
|
|
151
152
|
};
|
|
152
153
|
options: import("better-auth/plugins").GenericOAuthOptions;
|
|
153
154
|
$ERROR_CODES: {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
156
|
+
TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
157
|
+
PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
|
|
158
|
+
PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
|
|
159
|
+
INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
|
|
160
|
+
SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
|
|
161
|
+
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
162
|
+
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
160
163
|
};
|
|
161
164
|
}>;
|
|
165
|
+
$ERROR_CODES: {
|
|
166
|
+
INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
167
|
+
TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
168
|
+
PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
|
|
169
|
+
PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
|
|
170
|
+
INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
|
|
171
|
+
SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
|
|
172
|
+
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
173
|
+
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
174
|
+
};
|
|
162
175
|
}];
|
|
163
176
|
};
|
|
@@ -81,6 +81,7 @@ export declare function getBetterAuthOptions({ oidcDiscoveryUrl, authSecret, aut
|
|
|
81
81
|
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
82
82
|
error_description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
83
83
|
state: import("zod").ZodOptional<import("zod").ZodString>;
|
|
84
|
+
iss: import("zod").ZodOptional<import("zod").ZodString>;
|
|
84
85
|
}, import("better-auth").$strip>;
|
|
85
86
|
metadata: {
|
|
86
87
|
allowedMediaTypes: string[];
|
|
@@ -175,16 +176,22 @@ export declare function getBetterAuthOptions({ oidcDiscoveryUrl, authSecret, aut
|
|
|
175
176
|
};
|
|
176
177
|
options: import("better-auth/plugins").GenericOAuthOptions;
|
|
177
178
|
$ERROR_CODES: {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
180
|
+
TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
181
|
+
PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
|
|
182
|
+
PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
|
|
183
|
+
INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
|
|
184
|
+
SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
|
|
185
|
+
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
186
|
+
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
184
187
|
};
|
|
185
188
|
}, {
|
|
186
189
|
id: "next-cookies";
|
|
187
190
|
hooks: {
|
|
191
|
+
before: {
|
|
192
|
+
matcher(ctx: import("better-auth").HookEndpointContext): boolean;
|
|
193
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
194
|
+
}[];
|
|
188
195
|
after: {
|
|
189
196
|
matcher(ctx: import("better-auth").HookEndpointContext): true;
|
|
190
197
|
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtf/auth",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.3",
|
|
4
4
|
"description": "Better auth wrapper for imtf usage",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"schemas"
|
|
25
25
|
],
|
|
26
26
|
"prettier": "@imtf/prettier-config",
|
|
27
|
-
"module": "./lib/index.js",
|
|
27
|
+
"module": "./lib/index.esm.js",
|
|
28
28
|
"types": "./lib/types/index.d.ts",
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./lib/types/index.d.ts",
|
|
32
|
-
"import": "./lib/index.js"
|
|
32
|
+
"import": "./lib/index.esm.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@imtf/panache": "^5.6.0
|
|
36
|
+
"@imtf/panache": "^5.6.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@mui/lab": "^7.0.1-beta.18",
|