@imtf/auth 0.0.1-alpha.0 → 0.0.1-alpha.1
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 +3 -5
- package/lib/routes/getSignOutUrlRoute.js +4 -3
- package/lib/types/hooks/useSignOut.d.ts +2 -2
- package/lib/types/options/auth-client.d.ts +163 -2
- package/lib/types/options/auth.d.ts +190 -2
- package/lib/types/routes/getSignOutUrlRoute.d.ts +3 -3
- package/package.json +1 -1
package/lib/hooks/useSignOut.js
CHANGED
|
@@ -3,19 +3,17 @@ import { useCallback } from "react";
|
|
|
3
3
|
function useSignOut({
|
|
4
4
|
postLogoutRedirectPath = "/auth/sign-in?logout=success",
|
|
5
5
|
retrieveLogoutUrlPath = "/api/auth/sign-out-url",
|
|
6
|
-
|
|
6
|
+
onLogoutSuccess,
|
|
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:
|
|
14
|
-
navigate(postLogoutRedirectPath);
|
|
15
|
-
}
|
|
13
|
+
onSuccess: onLogoutSuccess
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
}, [authClient,
|
|
16
|
+
}, [authClient, onLogoutSuccess]);
|
|
19
17
|
const handleSignOut = useCallback(async () => {
|
|
20
18
|
const postLogoutRedirectUri = `${origin}${postLogoutRedirectPath}`;
|
|
21
19
|
try {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { PROVIDER_ID } from "../constants.js";
|
|
1
2
|
function getSignOutUrlRoute({
|
|
2
3
|
auth,
|
|
3
|
-
federatedLogout = true,
|
|
4
4
|
discoveryUrl,
|
|
5
|
-
|
|
5
|
+
federatedLogout = true,
|
|
6
|
+
providerId = PROVIDER_ID,
|
|
6
7
|
headers
|
|
7
8
|
}) {
|
|
8
9
|
return async function GET(request) {
|
|
9
10
|
try {
|
|
10
|
-
if (!federatedLogout) {
|
|
11
|
+
if (!federatedLogout || !discoveryUrl) {
|
|
11
12
|
return Response.json({ url: null }, { status: 200 });
|
|
12
13
|
}
|
|
13
14
|
const token = await auth.api.getAccessToken({
|
|
@@ -12,10 +12,10 @@ import type { getBetterAuthClientOptions } from "../index";
|
|
|
12
12
|
* const { handleSignOut } = useSignOut({ postLogoutRedirectPath: "/auth/sign-in" });
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export declare function useSignOut({ postLogoutRedirectPath, retrieveLogoutUrlPath,
|
|
15
|
+
export declare function useSignOut({ postLogoutRedirectPath, retrieveLogoutUrlPath, onLogoutSuccess, authClient, origin, }: {
|
|
16
16
|
postLogoutRedirectPath?: string;
|
|
17
17
|
retrieveLogoutUrlPath?: string;
|
|
18
|
-
|
|
18
|
+
onLogoutSuccess?: () => void;
|
|
19
19
|
authClient: AuthClient<ReturnType<typeof getBetterAuthClientOptions>>;
|
|
20
20
|
origin?: string;
|
|
21
21
|
}): {
|
|
@@ -1,2 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare function getBetterAuthClientOptions(): {
|
|
2
|
+
readonly plugins: [{
|
|
3
|
+
id: "generic-oauth-client";
|
|
4
|
+
$InferServerPlugin: ReturnType<(options: import("better-auth/plugins").GenericOAuthOptions) => {
|
|
5
|
+
id: "generic-oauth";
|
|
6
|
+
init: (ctx: import("better-auth").AuthContext) => {
|
|
7
|
+
context: {
|
|
8
|
+
socialProviders: import("better-auth").OAuthProvider<Record<string, any>, Partial<import("better-auth").ProviderOptions<any>>>[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
endpoints: {
|
|
12
|
+
signInWithOAuth2: import("better-call").StrictEndpoint<"/sign-in/oauth2", {
|
|
13
|
+
method: "POST";
|
|
14
|
+
body: import("zod").ZodObject<{
|
|
15
|
+
providerId: import("zod").ZodString;
|
|
16
|
+
callbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
17
|
+
errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
newUserCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
+
disableRedirect: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
20
|
+
scopes: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
21
|
+
requestSignUp: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
22
|
+
additionalData: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
|
|
23
|
+
}, import("better-auth").$strip>;
|
|
24
|
+
metadata: {
|
|
25
|
+
openapi: {
|
|
26
|
+
description: string;
|
|
27
|
+
responses: {
|
|
28
|
+
200: {
|
|
29
|
+
description: string;
|
|
30
|
+
content: {
|
|
31
|
+
"application/json": {
|
|
32
|
+
schema: {
|
|
33
|
+
type: "object";
|
|
34
|
+
properties: {
|
|
35
|
+
url: {
|
|
36
|
+
type: string;
|
|
37
|
+
};
|
|
38
|
+
redirect: {
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}, {
|
|
50
|
+
url: string;
|
|
51
|
+
redirect: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
oAuth2Callback: import("better-call").StrictEndpoint<"/oauth2/callback/:providerId", {
|
|
54
|
+
method: "GET";
|
|
55
|
+
query: import("zod").ZodObject<{
|
|
56
|
+
code: import("zod").ZodOptional<import("zod").ZodString>;
|
|
57
|
+
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
58
|
+
error_description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
59
|
+
state: import("zod").ZodOptional<import("zod").ZodString>;
|
|
60
|
+
}, import("better-auth").$strip>;
|
|
61
|
+
metadata: {
|
|
62
|
+
allowedMediaTypes: string[];
|
|
63
|
+
openapi: {
|
|
64
|
+
description: string;
|
|
65
|
+
responses: {
|
|
66
|
+
200: {
|
|
67
|
+
description: string;
|
|
68
|
+
content: {
|
|
69
|
+
"application/json": {
|
|
70
|
+
schema: {
|
|
71
|
+
type: "object";
|
|
72
|
+
properties: {
|
|
73
|
+
url: {
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
scope: "server";
|
|
84
|
+
};
|
|
85
|
+
}, void>;
|
|
86
|
+
oAuth2LinkAccount: import("better-call").StrictEndpoint<"/oauth2/link", {
|
|
87
|
+
method: "POST";
|
|
88
|
+
body: import("zod").ZodObject<{
|
|
89
|
+
providerId: import("zod").ZodString;
|
|
90
|
+
callbackURL: import("zod").ZodString;
|
|
91
|
+
scopes: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
92
|
+
errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
93
|
+
}, import("better-auth").$strip>;
|
|
94
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
95
|
+
session: {
|
|
96
|
+
session: Record<string, any> & {
|
|
97
|
+
id: string;
|
|
98
|
+
createdAt: Date;
|
|
99
|
+
updatedAt: Date;
|
|
100
|
+
userId: string;
|
|
101
|
+
expiresAt: Date;
|
|
102
|
+
token: string;
|
|
103
|
+
ipAddress?: string | null | undefined;
|
|
104
|
+
userAgent?: string | null | undefined;
|
|
105
|
+
};
|
|
106
|
+
user: Record<string, any> & {
|
|
107
|
+
id: string;
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
updatedAt: Date;
|
|
110
|
+
email: string;
|
|
111
|
+
emailVerified: boolean;
|
|
112
|
+
name: string;
|
|
113
|
+
image?: string | null | undefined;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}>)[];
|
|
117
|
+
metadata: {
|
|
118
|
+
openapi: {
|
|
119
|
+
description: string;
|
|
120
|
+
responses: {
|
|
121
|
+
"200": {
|
|
122
|
+
description: string;
|
|
123
|
+
content: {
|
|
124
|
+
"application/json": {
|
|
125
|
+
schema: {
|
|
126
|
+
type: "object";
|
|
127
|
+
properties: {
|
|
128
|
+
url: {
|
|
129
|
+
type: string;
|
|
130
|
+
format: string;
|
|
131
|
+
description: string;
|
|
132
|
+
};
|
|
133
|
+
redirect: {
|
|
134
|
+
type: string;
|
|
135
|
+
description: string;
|
|
136
|
+
enum: boolean[];
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
required: string[];
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
}, {
|
|
148
|
+
url: string;
|
|
149
|
+
redirect: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
};
|
|
152
|
+
options: import("better-auth/plugins").GenericOAuthOptions;
|
|
153
|
+
$ERROR_CODES: {
|
|
154
|
+
readonly INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration";
|
|
155
|
+
readonly TOKEN_URL_NOT_FOUND: "Invalid OAuth configuration. Token URL not found.";
|
|
156
|
+
readonly PROVIDER_CONFIG_NOT_FOUND: "No config found for provider";
|
|
157
|
+
readonly PROVIDER_ID_REQUIRED: "Provider ID is required";
|
|
158
|
+
readonly INVALID_OAUTH_CONFIG: "Invalid OAuth configuration.";
|
|
159
|
+
readonly SESSION_REQUIRED: "Session is required";
|
|
160
|
+
};
|
|
161
|
+
}>;
|
|
162
|
+
}];
|
|
163
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type BetterAuthOptions } from "better-auth";
|
|
2
1
|
export declare function getBetterAuthOptions({ oidcDiscoveryUrl, authSecret, authBaseURL, authClientId, authClientSecret, providerId, }: {
|
|
3
2
|
oidcDiscoveryUrl: string;
|
|
4
3
|
authSecret: string;
|
|
@@ -6,4 +5,193 @@ export declare function getBetterAuthOptions({ oidcDiscoveryUrl, authSecret, aut
|
|
|
6
5
|
authClientSecret: string;
|
|
7
6
|
providerId?: string;
|
|
8
7
|
authBaseURL?: string;
|
|
9
|
-
}):
|
|
8
|
+
}): {
|
|
9
|
+
readonly secret: string;
|
|
10
|
+
readonly baseURL: string | undefined;
|
|
11
|
+
readonly session: {
|
|
12
|
+
readonly cookieCache: {
|
|
13
|
+
readonly enabled: true;
|
|
14
|
+
readonly version: "1";
|
|
15
|
+
readonly maxAge: number;
|
|
16
|
+
readonly strategy: "compact";
|
|
17
|
+
readonly refreshCache: true;
|
|
18
|
+
};
|
|
19
|
+
readonly expiresIn: number;
|
|
20
|
+
readonly updateAge: number;
|
|
21
|
+
readonly freshAge: number;
|
|
22
|
+
};
|
|
23
|
+
readonly account: {
|
|
24
|
+
readonly updateAccountOnSignIn: true;
|
|
25
|
+
readonly storeStateStrategy: "cookie";
|
|
26
|
+
readonly storeAccountCookie: true;
|
|
27
|
+
};
|
|
28
|
+
readonly plugins: [{
|
|
29
|
+
id: "generic-oauth";
|
|
30
|
+
init: (ctx: import("better-auth").AuthContext) => {
|
|
31
|
+
context: {
|
|
32
|
+
socialProviders: import("better-auth").OAuthProvider<Record<string, any>, Partial<import("better-auth").ProviderOptions<any>>>[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
endpoints: {
|
|
36
|
+
signInWithOAuth2: import("better-call").StrictEndpoint<"/sign-in/oauth2", {
|
|
37
|
+
method: "POST";
|
|
38
|
+
body: import("zod").ZodObject<{
|
|
39
|
+
providerId: import("zod").ZodString;
|
|
40
|
+
callbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
41
|
+
errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
42
|
+
newUserCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
43
|
+
disableRedirect: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
44
|
+
scopes: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
45
|
+
requestSignUp: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
46
|
+
additionalData: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
|
|
47
|
+
}, import("better-auth").$strip>;
|
|
48
|
+
metadata: {
|
|
49
|
+
openapi: {
|
|
50
|
+
description: string;
|
|
51
|
+
responses: {
|
|
52
|
+
200: {
|
|
53
|
+
description: string;
|
|
54
|
+
content: {
|
|
55
|
+
"application/json": {
|
|
56
|
+
schema: {
|
|
57
|
+
type: "object";
|
|
58
|
+
properties: {
|
|
59
|
+
url: {
|
|
60
|
+
type: string;
|
|
61
|
+
};
|
|
62
|
+
redirect: {
|
|
63
|
+
type: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}, {
|
|
74
|
+
url: string;
|
|
75
|
+
redirect: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
oAuth2Callback: import("better-call").StrictEndpoint<"/oauth2/callback/:providerId", {
|
|
78
|
+
method: "GET";
|
|
79
|
+
query: import("zod").ZodObject<{
|
|
80
|
+
code: import("zod").ZodOptional<import("zod").ZodString>;
|
|
81
|
+
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
82
|
+
error_description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
83
|
+
state: import("zod").ZodOptional<import("zod").ZodString>;
|
|
84
|
+
}, import("better-auth").$strip>;
|
|
85
|
+
metadata: {
|
|
86
|
+
allowedMediaTypes: string[];
|
|
87
|
+
openapi: {
|
|
88
|
+
description: string;
|
|
89
|
+
responses: {
|
|
90
|
+
200: {
|
|
91
|
+
description: string;
|
|
92
|
+
content: {
|
|
93
|
+
"application/json": {
|
|
94
|
+
schema: {
|
|
95
|
+
type: "object";
|
|
96
|
+
properties: {
|
|
97
|
+
url: {
|
|
98
|
+
type: string;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
scope: "server";
|
|
108
|
+
};
|
|
109
|
+
}, void>;
|
|
110
|
+
oAuth2LinkAccount: import("better-call").StrictEndpoint<"/oauth2/link", {
|
|
111
|
+
method: "POST";
|
|
112
|
+
body: import("zod").ZodObject<{
|
|
113
|
+
providerId: import("zod").ZodString;
|
|
114
|
+
callbackURL: import("zod").ZodString;
|
|
115
|
+
scopes: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
116
|
+
errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
117
|
+
}, import("better-auth").$strip>;
|
|
118
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
119
|
+
session: {
|
|
120
|
+
session: Record<string, any> & {
|
|
121
|
+
id: string;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
updatedAt: Date;
|
|
124
|
+
userId: string;
|
|
125
|
+
expiresAt: Date;
|
|
126
|
+
token: string;
|
|
127
|
+
ipAddress?: string | null | undefined;
|
|
128
|
+
userAgent?: string | null | undefined;
|
|
129
|
+
};
|
|
130
|
+
user: Record<string, any> & {
|
|
131
|
+
id: string;
|
|
132
|
+
createdAt: Date;
|
|
133
|
+
updatedAt: Date;
|
|
134
|
+
email: string;
|
|
135
|
+
emailVerified: boolean;
|
|
136
|
+
name: string;
|
|
137
|
+
image?: string | null | undefined;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}>)[];
|
|
141
|
+
metadata: {
|
|
142
|
+
openapi: {
|
|
143
|
+
description: string;
|
|
144
|
+
responses: {
|
|
145
|
+
"200": {
|
|
146
|
+
description: string;
|
|
147
|
+
content: {
|
|
148
|
+
"application/json": {
|
|
149
|
+
schema: {
|
|
150
|
+
type: "object";
|
|
151
|
+
properties: {
|
|
152
|
+
url: {
|
|
153
|
+
type: string;
|
|
154
|
+
format: string;
|
|
155
|
+
description: string;
|
|
156
|
+
};
|
|
157
|
+
redirect: {
|
|
158
|
+
type: string;
|
|
159
|
+
description: string;
|
|
160
|
+
enum: boolean[];
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
required: string[];
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
}, {
|
|
172
|
+
url: string;
|
|
173
|
+
redirect: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
};
|
|
176
|
+
options: import("better-auth/plugins").GenericOAuthOptions;
|
|
177
|
+
$ERROR_CODES: {
|
|
178
|
+
readonly INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration";
|
|
179
|
+
readonly TOKEN_URL_NOT_FOUND: "Invalid OAuth configuration. Token URL not found.";
|
|
180
|
+
readonly PROVIDER_CONFIG_NOT_FOUND: "No config found for provider";
|
|
181
|
+
readonly PROVIDER_ID_REQUIRED: "Provider ID is required";
|
|
182
|
+
readonly INVALID_OAUTH_CONFIG: "Invalid OAuth configuration.";
|
|
183
|
+
readonly SESSION_REQUIRED: "Session is required";
|
|
184
|
+
};
|
|
185
|
+
}, {
|
|
186
|
+
id: "next-cookies";
|
|
187
|
+
hooks: {
|
|
188
|
+
after: {
|
|
189
|
+
matcher(ctx: import("better-auth").HookEndpointContext): true;
|
|
190
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
191
|
+
}[];
|
|
192
|
+
};
|
|
193
|
+
}];
|
|
194
|
+
readonly onAPIError: {
|
|
195
|
+
readonly errorURL: "/auth/error";
|
|
196
|
+
};
|
|
197
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Auth } from "better-auth";
|
|
2
2
|
import { headers as nextHeaders } from "next/headers";
|
|
3
3
|
import type { NextRequest } from "next/server";
|
|
4
|
-
export declare function getSignOutUrlRoute({ auth,
|
|
4
|
+
export declare function getSignOutUrlRoute({ auth, discoveryUrl, federatedLogout, providerId, headers, }: {
|
|
5
5
|
auth: Auth;
|
|
6
|
+
discoveryUrl?: string;
|
|
6
7
|
federatedLogout?: boolean;
|
|
7
|
-
|
|
8
|
-
providerId: string;
|
|
8
|
+
providerId?: string;
|
|
9
9
|
headers: typeof nextHeaders;
|
|
10
10
|
}): (request: NextRequest) => Promise<Response>;
|