@krak-stack/auth 0.1.38 → 0.1.39
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/api.d.ts +6 -0
- package/dist/better-auth/api.d.ts +2 -0
- package/dist/better-auth/index.d.ts +1 -0
- package/dist/better-auth/schema.d.ts +1 -0
- package/dist/better-auth/schema.js +1 -0
- package/dist/components/auth-api-client.d.ts +6 -0
- package/dist/components/auth-client.d.ts +2 -1
- package/dist/components/auth-forms.js +10 -24
- package/dist/components/auth-provider.js +24 -2
- package/dist/components/user-button.js +19 -12
- package/dist/extra/api.d.ts +2 -0
- package/dist/extra/index.d.ts +1 -0
- package/dist/extra/schema.d.ts +1 -0
- package/dist/extra/schema.js +2 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +3 -0
- package/dist/server/api.d.ts +8 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +1 -0
- package/dist/server/middleware.d.ts +23 -0
- package/dist/server/middleware.js +40 -0
- package/dist/server/schema.d.ts +2 -0
- package/dist/service.d.ts +86 -35
- package/dist/service.js +96 -12
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
20
20
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
21
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
22
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
23
24
|
readonly createdAt: import("effect/Schema").Date;
|
|
24
25
|
readonly updatedAt: import("effect/Schema").Date;
|
|
25
26
|
}>;
|
|
@@ -35,6 +36,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
35
36
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
36
37
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
37
38
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
39
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
38
40
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
39
41
|
readonly projectKey: import("effect/Schema").String;
|
|
40
42
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -170,6 +172,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
170
172
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
171
173
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
172
174
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
175
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
173
176
|
readonly createdAt: import("effect/Schema").Date;
|
|
174
177
|
readonly updatedAt: import("effect/Schema").Date;
|
|
175
178
|
}>;
|
|
@@ -207,6 +210,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
207
210
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
208
211
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
209
212
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
213
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
210
214
|
readonly createdAt: import("effect/Schema").Date;
|
|
211
215
|
readonly updatedAt: import("effect/Schema").Date;
|
|
212
216
|
}>;
|
|
@@ -242,6 +246,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
242
246
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
243
247
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
244
248
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
249
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
245
250
|
readonly createdAt: import("effect/Schema").Date;
|
|
246
251
|
readonly updatedAt: import("effect/Schema").Date;
|
|
247
252
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getUserActiveOrganization", "GET", "/api/organizations/user/:userId/active", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
@@ -259,6 +264,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
259
264
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
260
265
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
261
266
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
267
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
262
268
|
readonly createdAt: import("effect/Schema").Date;
|
|
263
269
|
readonly updatedAt: import("effect/Schema").Date;
|
|
264
270
|
}>>;
|
|
@@ -22,6 +22,7 @@ export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpA
|
|
|
22
22
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
23
23
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
24
24
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
25
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
25
26
|
readonly createdAt: import("effect/Schema").Date;
|
|
26
27
|
readonly updatedAt: import("effect/Schema").Date;
|
|
27
28
|
}>;
|
|
@@ -47,6 +48,7 @@ export declare const BetterAuthApi: HttpApi.HttpApi<"BetterAuthApi", HttpApiGrou
|
|
|
47
48
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
48
49
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
49
50
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
51
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
50
52
|
readonly createdAt: import("effect/Schema").Date;
|
|
51
53
|
readonly updatedAt: import("effect/Schema").Date;
|
|
52
54
|
}>;
|
|
@@ -20,6 +20,7 @@ declare const BetterAuthApiClient_base: AtomHttpApi.AtomHttpApiClient<BetterAuth
|
|
|
20
20
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
21
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
22
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
23
24
|
readonly createdAt: import("effect/Schema").Date;
|
|
24
25
|
readonly updatedAt: import("effect/Schema").Date;
|
|
25
26
|
}>;
|
|
@@ -21,6 +21,7 @@ export declare const GetSessionResponse: Schema.NullOr<Schema.Struct<{
|
|
|
21
21
|
readonly image: Schema.NullOr<Schema.String>;
|
|
22
22
|
readonly role: Schema.NullOr<Schema.String>;
|
|
23
23
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
24
|
+
readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
24
25
|
readonly createdAt: Schema.Date;
|
|
25
26
|
readonly updatedAt: Schema.Date;
|
|
26
27
|
}>;
|
|
@@ -20,6 +20,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
20
20
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
21
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
22
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
23
24
|
readonly createdAt: import("effect/Schema").Date;
|
|
24
25
|
readonly updatedAt: import("effect/Schema").Date;
|
|
25
26
|
}>;
|
|
@@ -35,6 +36,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
35
36
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
36
37
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
37
38
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
39
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
38
40
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
39
41
|
readonly projectKey: import("effect/Schema").String;
|
|
40
42
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -170,6 +172,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
170
172
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
171
173
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
172
174
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
175
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
173
176
|
readonly createdAt: import("effect/Schema").Date;
|
|
174
177
|
readonly updatedAt: import("effect/Schema").Date;
|
|
175
178
|
}>;
|
|
@@ -207,6 +210,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
207
210
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
208
211
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
209
212
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
213
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
210
214
|
readonly createdAt: import("effect/Schema").Date;
|
|
211
215
|
readonly updatedAt: import("effect/Schema").Date;
|
|
212
216
|
}>;
|
|
@@ -242,6 +246,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
242
246
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
243
247
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
244
248
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
249
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
245
250
|
readonly createdAt: import("effect/Schema").Date;
|
|
246
251
|
readonly updatedAt: import("effect/Schema").Date;
|
|
247
252
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getUserActiveOrganization", "GET", "/api/organizations/user/:userId/active", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
@@ -259,6 +264,7 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
259
264
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
260
265
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
261
266
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
267
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
262
268
|
readonly createdAt: import("effect/Schema").Date;
|
|
263
269
|
readonly updatedAt: import("effect/Schema").Date;
|
|
264
270
|
}>>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
-
import type { emailOTPClient, genericOAuthClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
2
|
+
import type { emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
3
3
|
import type { createAuthClient } from "better-auth/react";
|
|
4
4
|
export type AuthUiClient = ReturnType<typeof createAuthClient<{
|
|
5
5
|
plugins: [
|
|
6
6
|
ReturnType<typeof emailOTPClient>,
|
|
7
|
+
ReturnType<typeof lastLoginMethodClient>,
|
|
7
8
|
ReturnType<typeof organizationClient>,
|
|
8
9
|
ReturnType<typeof twoFactorClient>,
|
|
9
10
|
ReturnType<typeof apiKeyClient>,
|
|
@@ -161,6 +161,7 @@ const useAuthProjectConfig = (baseUrl, searchString, projectConfig) => {
|
|
|
161
161
|
};
|
|
162
162
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
163
163
|
const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
|
|
164
|
+
const lastLoginMethodToAuthMethod = (method) => method === "email" ? "password" : "emailOtp";
|
|
164
165
|
const searchObject = (searchString) => Object.fromEntries(new URLSearchParams(searchString));
|
|
165
166
|
export function Signin(props) {
|
|
166
167
|
const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
|
|
@@ -182,7 +183,7 @@ export function Signin(props) {
|
|
|
182
183
|
signUp: authOptions.signUp ?? true,
|
|
183
184
|
};
|
|
184
185
|
const [emailSubmitted, setEmailSubmitted] = useState(false);
|
|
185
|
-
const [authMethod, setAuthMethod] = useState(
|
|
186
|
+
const [authMethod, setAuthMethod] = useState(() => lastLoginMethodToAuthMethod(authClient.getLastUsedLoginMethod?.()));
|
|
186
187
|
const [otpSentTo, setOtpSentTo] = useState("");
|
|
187
188
|
const [emailOtpResendAvailableAt, setEmailOtpResendAvailableAt] = useState(0);
|
|
188
189
|
const [emailOtpResendSeconds, setEmailOtpResendSeconds] = useState(0);
|
|
@@ -349,7 +350,12 @@ export function Signin(props) {
|
|
|
349
350
|
event.preventDefault();
|
|
350
351
|
event.stopPropagation();
|
|
351
352
|
form.handleSubmit();
|
|
352
|
-
}, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email",
|
|
353
|
+
}, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
|
|
354
|
+
if (event.key !== "Enter")
|
|
355
|
+
return;
|
|
356
|
+
event.preventDefault();
|
|
357
|
+
form.handleSubmit();
|
|
358
|
+
}, required: true })) })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "current-password", required: true })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "otp", children: (field) => (_jsx(OtpInput, { field: field, label: m.sign_in_email_otp_code })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
|
|
353
359
|
? text(m.sign_in_email_otp_resend_countdown, {
|
|
354
360
|
seconds: String(emailOtpResendSeconds),
|
|
355
361
|
})
|
|
@@ -635,28 +641,8 @@ const getAuthRedirectParam = (searchString) => {
|
|
|
635
641
|
search.get("redirectTo") ??
|
|
636
642
|
search.get("returnTo"));
|
|
637
643
|
};
|
|
638
|
-
const getDefaultAuthRedirectTarget = (
|
|
639
|
-
|
|
640
|
-
return "/admin";
|
|
641
|
-
const currentHost = normalizeAuthHost(window.location.host);
|
|
642
|
-
const isProjectDomain = normalizeAuthHost(projectAuthDomain) === currentHost;
|
|
643
|
-
if (!isProjectDomain)
|
|
644
|
-
return "/admin";
|
|
645
|
-
const rootDomain = normalizeAuthHost(projectRootDomain);
|
|
646
|
-
if (!rootDomain)
|
|
647
|
-
return "/admin";
|
|
648
|
-
return `${window.location.protocol}//${rootDomain}`;
|
|
649
|
-
};
|
|
650
|
-
const normalizeAuthHost = (value) => {
|
|
651
|
-
const raw = value?.trim().toLowerCase();
|
|
652
|
-
if (!raw)
|
|
653
|
-
return null;
|
|
654
|
-
try {
|
|
655
|
-
return new URL(raw.includes("://") ? raw : `https://${raw}`).host;
|
|
656
|
-
}
|
|
657
|
-
catch {
|
|
658
|
-
return raw.split("/")[0]?.trim() || null;
|
|
659
|
-
}
|
|
644
|
+
const getDefaultAuthRedirectTarget = (_projectAuthDomain, _projectRootDomain) => {
|
|
645
|
+
return "/admin";
|
|
660
646
|
};
|
|
661
647
|
const getSearchParam = (searchString, key) => new URLSearchParams(searchString).get(key);
|
|
662
648
|
const getBrowserAuthHost = () => typeof window === "undefined" ? null : window.location.host;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
3
3
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
4
4
|
import { useRouterState } from "@tanstack/react-router";
|
|
5
|
-
import { emailOTPClient, genericOAuthClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
5
|
+
import { emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
6
6
|
import { createAuthClient } from "better-auth/react";
|
|
7
7
|
import { createContext, useContext, useMemo } from "react";
|
|
8
8
|
import { authApiClient } from "./auth-api-client";
|
|
@@ -11,6 +11,7 @@ const createAuthUiClient = (baseUrl) => createAuthClient({
|
|
|
11
11
|
...(baseUrl ? { baseURL: baseUrl } : {}),
|
|
12
12
|
plugins: [
|
|
13
13
|
emailOTPClient(),
|
|
14
|
+
lastLoginMethodClient(),
|
|
14
15
|
organizationClient(),
|
|
15
16
|
twoFactorClient(),
|
|
16
17
|
apiKeyClient(),
|
|
@@ -23,6 +24,24 @@ const getSearchParam = (searchString, key) => {
|
|
|
23
24
|
return new URLSearchParams(searchString).get(key);
|
|
24
25
|
};
|
|
25
26
|
const getBrowserAuthHost = () => typeof window === "undefined" ? null : window.location.host;
|
|
27
|
+
const getRedirectHost = (searchString) => {
|
|
28
|
+
if (!searchString)
|
|
29
|
+
return null;
|
|
30
|
+
const search = new URLSearchParams(searchString);
|
|
31
|
+
const target = search.get("callbackURL") ??
|
|
32
|
+
search.get("redirect") ??
|
|
33
|
+
search.get("redirectTo") ??
|
|
34
|
+
search.get("returnTo") ??
|
|
35
|
+
search.get("redirect_uri");
|
|
36
|
+
if (!target)
|
|
37
|
+
return null;
|
|
38
|
+
try {
|
|
39
|
+
return new URL(target).host;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
26
45
|
const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
27
46
|
const searchString = useRouterState({
|
|
28
47
|
select: (state) => state.location.searchStr,
|
|
@@ -30,11 +49,13 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
30
49
|
const projectId = providedProjectId ?? getSearchParam(searchString, "projectId");
|
|
31
50
|
const clientId = getSearchParam(searchString, "client_id");
|
|
32
51
|
const host = getBrowserAuthHost();
|
|
52
|
+
const rootHost = getRedirectHost(searchString);
|
|
33
53
|
const result = useAtomSuspense(authApiClient(baseUrl).query("authExtra", "getProjectPublicConfig", {
|
|
34
54
|
query: {
|
|
35
55
|
...(projectId ? { projectId } : {}),
|
|
36
56
|
...(clientId ? { clientId } : {}),
|
|
37
57
|
...(host ? { host } : {}),
|
|
58
|
+
...(rootHost ? { rootHost } : {}),
|
|
38
59
|
},
|
|
39
60
|
timeToLive: "5 minutes",
|
|
40
61
|
reactivityKeys: [
|
|
@@ -42,8 +63,9 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
42
63
|
...(projectId ? [`project:${projectId}`] : []),
|
|
43
64
|
...(clientId ? [`client:${clientId}`] : []),
|
|
44
65
|
...(host ? [`host:${host}`] : []),
|
|
66
|
+
...(rootHost ? [`root-host:${rootHost}`] : []),
|
|
45
67
|
],
|
|
46
|
-
serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}`,
|
|
68
|
+
serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}:${rootHost ?? ""}`,
|
|
47
69
|
}), { suspendOnWaiting: true });
|
|
48
70
|
return result.value;
|
|
49
71
|
};
|
|
@@ -18,6 +18,7 @@ import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLeg
|
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
20
|
import { authApiClient } from "./auth-api-client";
|
|
21
|
+
import { useKrakstackAuthProjectConfig } from "./auth-provider";
|
|
21
22
|
import { createApiKey } from "./api-key";
|
|
22
23
|
import { useOpenedOnce } from "./hooks";
|
|
23
24
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
@@ -219,6 +220,7 @@ const uploadUserImageAsset = async (file, m, uploadUserImage) => {
|
|
|
219
220
|
throw new Error(m.user_profile_image_upload_error());
|
|
220
221
|
}
|
|
221
222
|
};
|
|
223
|
+
const requiresPasswordForAccountRevoke = (accounts) => accounts.some((account) => account.providerId === "credential");
|
|
222
224
|
const userAccountsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
223
225
|
try: async () => {
|
|
224
226
|
const result = await authClient.listAccounts();
|
|
@@ -246,6 +248,7 @@ const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
|
246
248
|
export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
247
249
|
const labels = userButtonMessages(messages);
|
|
248
250
|
const m = userButtonMessageFns(labels);
|
|
251
|
+
const projectConfig = useKrakstackAuthProjectConfig();
|
|
249
252
|
const navigate = useNavigate();
|
|
250
253
|
const currentSiteHref = useRouterState({
|
|
251
254
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
@@ -331,21 +334,27 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
331
334
|
? error.message
|
|
332
335
|
: m.user_form_update_error());
|
|
333
336
|
}
|
|
334
|
-
} }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
|
|
337
|
+
} }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
|
|
335
338
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
336
339
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
337
340
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
338
341
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) })] }));
|
|
339
342
|
};
|
|
340
|
-
function ConnectedAccounts({ authClient, baseUrl, accountCache, currentSiteHref, navigate, }) {
|
|
343
|
+
function ConnectedAccounts({ authClient, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
341
344
|
const m = useUserButtonMessages();
|
|
345
|
+
const [error, setError] = useState(null);
|
|
342
346
|
const [isLinking, setIsLinking] = useState(false);
|
|
343
347
|
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
344
348
|
const accounts = accountCache.accounts ?? [];
|
|
345
349
|
const googleAccount = accounts.find((account) => account.providerId === "google");
|
|
346
|
-
const
|
|
347
|
-
const
|
|
350
|
+
const requirePassword = requiresPasswordForAccountRevoke(accounts);
|
|
351
|
+
const showGoogleAccount = googleEnabled || Boolean(googleAccount);
|
|
352
|
+
if (accountCache.accounts && (accounts.length === 0 || !showGoogleAccount)) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
348
355
|
const linkGoogle = async () => {
|
|
356
|
+
if (!googleEnabled)
|
|
357
|
+
return;
|
|
349
358
|
setError(null);
|
|
350
359
|
setIsLinking(true);
|
|
351
360
|
const result = await authClient.linkSocial({
|
|
@@ -376,13 +385,13 @@ function ConnectedAccounts({ authClient, baseUrl, accountCache, currentSiteHref,
|
|
|
376
385
|
setRevokingAccount(null);
|
|
377
386
|
await accountCache.reload();
|
|
378
387
|
};
|
|
379
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), accountCache.accounts ? (_jsxs(_Fragment, { children: [_jsx(AccountProviderRow, { icon: _jsx(GoogleLogo, {}), title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount),
|
|
388
|
+
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), accountCache.accounts ? (_jsxs(_Fragment, { children: [showGoogleAccount ? (_jsx(AccountProviderRow, { icon: _jsx(GoogleLogo, {}), title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) })) : null, revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: requirePassword, onCancel: () => setRevokingAccount(null), onRevoke: revokeAccount })) : null] })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
380
389
|
}
|
|
381
|
-
function AccountProviderRow({ icon, title, description, account, connected,
|
|
390
|
+
function AccountProviderRow({ icon, title, description, account, connected, connectLabel, revokeLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
|
|
382
391
|
const m = useUserButtonMessages();
|
|
383
392
|
return (_jsx("div", { className: "flex flex-col gap-3 rounded-lg border p-4", children: _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border text-sm font-semibold", children: icon }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: title }), _jsx(Badge, { variant: connected ? "default" : "secondary", children: connected
|
|
384
393
|
? m.user_account_connected()
|
|
385
|
-
: m.user_account_not_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: description })] })] }), connected && account ? (_jsx(Button, { type: "button", variant: "outline",
|
|
394
|
+
: m.user_account_not_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: description })] })] }), connected && account ? (_jsx(Button, { type: "button", variant: "outline", onClick: () => onRevoke(account), children: revokeLabel })) : renderDisconnected ? (renderDisconnected) : (_jsx(Button, { type: "button", variant: "outline", disabled: isConnecting, onClick: onConnect, children: connectLabel }))] }) }));
|
|
386
395
|
}
|
|
387
396
|
function GoogleLogo() {
|
|
388
397
|
return (_jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", className: "size-5", children: [_jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }), _jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }), _jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }), _jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" })] }));
|
|
@@ -394,7 +403,7 @@ function PasswordSettings({ authClient, baseUrl, accountCache, }) {
|
|
|
394
403
|
const accounts = accountCache.accounts ?? [];
|
|
395
404
|
const passwordAccount = accounts.find((account) => account.providerId === "credential");
|
|
396
405
|
const hasPassword = Boolean(passwordAccount);
|
|
397
|
-
const
|
|
406
|
+
const requirePassword = requiresPasswordForAccountRevoke(accounts);
|
|
398
407
|
const revokePassword = async (account) => {
|
|
399
408
|
setError(null);
|
|
400
409
|
const result = await authClient.unlinkAccount({
|
|
@@ -408,9 +417,7 @@ function PasswordSettings({ authClient, baseUrl, accountCache, }) {
|
|
|
408
417
|
setRevokingAccount(null);
|
|
409
418
|
await accountCache.reload();
|
|
410
419
|
};
|
|
411
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), accountCache.accounts && hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline",
|
|
412
|
-
? m.user_account_revoke()
|
|
413
|
-
: m.user_account_only_method() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: true, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { authClient: authClient })] })) : accountCache.accounts ? (_jsx(SetPasswordForm, { authClient: authClient, onSaved: accountCache.reload })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
420
|
+
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), accountCache.accounts && hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setRevokingAccount(passwordAccount), children: m.user_account_revoke() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: requirePassword, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { authClient: authClient })] })) : accountCache.accounts ? (_jsx(SetPasswordForm, { authClient: authClient, onSaved: accountCache.reload })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
414
421
|
}
|
|
415
422
|
function ChangePasswordForm({ authClient }) {
|
|
416
423
|
const m = useUserButtonMessages();
|
|
@@ -470,7 +477,7 @@ function SetPasswordForm({ authClient, onSaved, }) {
|
|
|
470
477
|
event.preventDefault();
|
|
471
478
|
event.stopPropagation();
|
|
472
479
|
form.handleSubmit();
|
|
473
|
-
}, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true })) }), _jsx(form.FormError, {}), _jsx(
|
|
480
|
+
}, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, { children: m.user_account_password_set() })] }) }));
|
|
474
481
|
}
|
|
475
482
|
function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
|
|
476
483
|
const m = useUserButtonMessages();
|
package/dist/extra/api.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
|
|
|
13
13
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
14
14
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
15
15
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
16
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
16
17
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
|
|
17
18
|
readonly projectKey: import("effect/Schema").String;
|
|
18
19
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -80,6 +81,7 @@ export declare const ExtraApi: HttpApi.HttpApi<"ExtraApi", HttpApiGroup.HttpApiG
|
|
|
80
81
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
81
82
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
82
83
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
84
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
83
85
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
|
|
84
86
|
readonly projectKey: import("effect/Schema").String;
|
|
85
87
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
package/dist/extra/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const ExtraApiClient_base: AtomHttpApi.AtomHttpApiClient<ExtraApiClient,
|
|
|
11
11
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
12
12
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
13
13
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
14
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
14
15
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
15
16
|
readonly projectKey: import("effect/Schema").String;
|
|
16
17
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
package/dist/extra/schema.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export declare const ExtraProjectPublicConfigQuery: Schema.Struct<{
|
|
|
73
73
|
readonly projectId: Schema.optional<Schema.String>;
|
|
74
74
|
readonly clientId: Schema.optional<Schema.String>;
|
|
75
75
|
readonly host: Schema.optional<Schema.String>;
|
|
76
|
+
readonly rootHost: Schema.optional<Schema.String>;
|
|
76
77
|
}>;
|
|
77
78
|
export declare const ExtraProjectAuthOptions: Schema.Struct<{
|
|
78
79
|
readonly emailPassword: Schema.Boolean;
|
package/dist/extra/schema.js
CHANGED
|
@@ -139,6 +139,7 @@ export const ExtraProjectPublicConfigQuery = Schema.Struct({
|
|
|
139
139
|
projectId: Schema.optional(Schema.String),
|
|
140
140
|
clientId: Schema.optional(Schema.String),
|
|
141
141
|
host: Schema.optional(Schema.String),
|
|
142
|
+
rootHost: Schema.optional(Schema.String),
|
|
142
143
|
}).annotate({
|
|
143
144
|
identifier: "ExtraProjectPublicConfigQuery",
|
|
144
145
|
title: "Extra project public config query",
|
|
@@ -147,6 +148,7 @@ export const ExtraProjectPublicConfigQuery = Schema.Struct({
|
|
|
147
148
|
{
|
|
148
149
|
projectId: "project-id",
|
|
149
150
|
host: "auth.example.com",
|
|
151
|
+
rootHost: "example.com",
|
|
150
152
|
clientId: "oauth-client-id",
|
|
151
153
|
},
|
|
152
154
|
],
|
package/dist/schema.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const User: Schema.Struct<{
|
|
|
7
7
|
readonly image: Schema.NullOr<Schema.String>;
|
|
8
8
|
readonly role: Schema.NullOr<Schema.String>;
|
|
9
9
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
10
|
+
readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
10
11
|
readonly createdAt: Schema.Date;
|
|
11
12
|
readonly updatedAt: Schema.Date;
|
|
12
13
|
}>;
|
|
@@ -72,6 +73,7 @@ export declare const Member: Schema.Struct<{
|
|
|
72
73
|
readonly image: Schema.NullOr<Schema.String>;
|
|
73
74
|
readonly role: Schema.NullOr<Schema.String>;
|
|
74
75
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
76
|
+
readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
75
77
|
readonly createdAt: Schema.Date;
|
|
76
78
|
readonly updatedAt: Schema.Date;
|
|
77
79
|
}>;
|
package/dist/schema.js
CHANGED
|
@@ -7,6 +7,7 @@ export const User = Schema.Struct({
|
|
|
7
7
|
image: Schema.NullOr(Schema.String),
|
|
8
8
|
role: Schema.NullOr(Schema.String),
|
|
9
9
|
banned: Schema.NullOr(Schema.Boolean),
|
|
10
|
+
lastLoginMethod: Schema.optional(Schema.NullOr(Schema.String)),
|
|
10
11
|
createdAt: Schema.Date,
|
|
11
12
|
updatedAt: Schema.Date,
|
|
12
13
|
}).annotate({
|
|
@@ -22,6 +23,7 @@ export const User = Schema.Struct({
|
|
|
22
23
|
image: null,
|
|
23
24
|
role: "admin",
|
|
24
25
|
banned: false,
|
|
26
|
+
lastLoginMethod: "email-otp",
|
|
25
27
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
26
28
|
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
27
29
|
},
|
|
@@ -168,6 +170,7 @@ export const Member = Schema.Struct({
|
|
|
168
170
|
image: null,
|
|
169
171
|
role: "admin",
|
|
170
172
|
banned: false,
|
|
173
|
+
lastLoginMethod: "email-otp",
|
|
171
174
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
172
175
|
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
173
176
|
},
|
package/dist/server/api.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare const ServerUsersApiGroup: HttpApiGroup.HttpApiGroup<"users", Htt
|
|
|
10
10
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
11
11
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
12
12
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
13
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
13
14
|
readonly createdAt: import("effect/Schema").Date;
|
|
14
15
|
readonly updatedAt: import("effect/Schema").Date;
|
|
15
16
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getUserActiveOrganization", "GET", "/organizations/user/:userId/active", HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
|
|
@@ -27,6 +28,7 @@ export declare const ServerUsersApiGroup: HttpApiGroup.HttpApiGroup<"users", Htt
|
|
|
27
28
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
28
29
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
29
30
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
31
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
30
32
|
readonly createdAt: import("effect/Schema").Date;
|
|
31
33
|
readonly updatedAt: import("effect/Schema").Date;
|
|
32
34
|
}>>;
|
|
@@ -49,6 +51,7 @@ export declare const ServerOrganizationsApiGroup: HttpApiGroup.HttpApiGroup<"org
|
|
|
49
51
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
50
52
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
51
53
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
54
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
52
55
|
readonly createdAt: import("effect/Schema").Date;
|
|
53
56
|
readonly updatedAt: import("effect/Schema").Date;
|
|
54
57
|
}>;
|
|
@@ -86,6 +89,7 @@ export declare const ServerOrganizationsApiGroup: HttpApiGroup.HttpApiGroup<"org
|
|
|
86
89
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
87
90
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
88
91
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
92
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
89
93
|
readonly createdAt: import("effect/Schema").Date;
|
|
90
94
|
readonly updatedAt: import("effect/Schema").Date;
|
|
91
95
|
}>;
|
|
@@ -258,6 +262,7 @@ export declare const ServerApi: HttpApi.HttpApi<"ServerApi", HttpApiGroup.HttpAp
|
|
|
258
262
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
259
263
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
260
264
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
265
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
261
266
|
readonly createdAt: import("effect/Schema").Date;
|
|
262
267
|
readonly updatedAt: import("effect/Schema").Date;
|
|
263
268
|
}>;
|
|
@@ -295,6 +300,7 @@ export declare const ServerApi: HttpApi.HttpApi<"ServerApi", HttpApiGroup.HttpAp
|
|
|
295
300
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
296
301
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
297
302
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
303
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
298
304
|
readonly createdAt: import("effect/Schema").Date;
|
|
299
305
|
readonly updatedAt: import("effect/Schema").Date;
|
|
300
306
|
}>;
|
|
@@ -330,6 +336,7 @@ export declare const ServerApi: HttpApi.HttpApi<"ServerApi", HttpApiGroup.HttpAp
|
|
|
330
336
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
331
337
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
332
338
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
339
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
333
340
|
readonly createdAt: import("effect/Schema").Date;
|
|
334
341
|
readonly updatedAt: import("effect/Schema").Date;
|
|
335
342
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getUserActiveOrganization", "GET", "/api/organizations/user/:userId/active", HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
|
|
@@ -347,6 +354,7 @@ export declare const ServerApi: HttpApi.HttpApi<"ServerApi", HttpApiGroup.HttpAp
|
|
|
347
354
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
348
355
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
349
356
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
357
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
350
358
|
readonly createdAt: import("effect/Schema").Date;
|
|
351
359
|
readonly updatedAt: import("effect/Schema").Date;
|
|
352
360
|
}>>;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { AuthService } from "../service";
|
|
2
|
+
export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service";
|
|
2
3
|
export { AuthClientConfig } from "../config";
|
|
3
4
|
export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
|
|
4
5
|
export { proxyAuthRequest } from "./proxy";
|
|
6
|
+
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
|
7
|
+
export type { AuthenticationLiveOptions } from "./middleware";
|
|
5
8
|
export type { ServerActiveOrganization, ServerMembersResponse, ServerOrganizationsResponse, ServerUsersResponse, } from "./schema";
|
|
6
9
|
export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
|
package/dist/server/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { AuthService } from "../service";
|
|
|
2
2
|
export { AuthClientConfig } from "../config";
|
|
3
3
|
export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
|
|
4
4
|
export { proxyAuthRequest } from "./proxy";
|
|
5
|
+
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
3
|
+
import { AuthService, type AuthServiceLayerOptions } from "../service";
|
|
4
|
+
export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
|
|
5
|
+
declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware, "@krak-stack/auth/AuthMiddleware", {
|
|
6
|
+
requires: never;
|
|
7
|
+
provides: AuthService;
|
|
8
|
+
error: typeof HttpApiError.Unauthorized;
|
|
9
|
+
clientError: never;
|
|
10
|
+
requiredForClient: false;
|
|
11
|
+
security: {
|
|
12
|
+
readonly apiKey: HttpApiSecurity.ApiKey;
|
|
13
|
+
};
|
|
14
|
+
}, HttpApiMiddleware.HttpApiMiddlewareSecurity<{
|
|
15
|
+
readonly apiKey: HttpApiSecurity.ApiKey;
|
|
16
|
+
}, AuthService, typeof HttpApiError.Unauthorized, never>>;
|
|
17
|
+
export declare class AuthMiddleware extends AuthMiddleware_base {
|
|
18
|
+
}
|
|
19
|
+
export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
|
|
20
|
+
readonly authLayer?: Layer.Layer<AuthService, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export declare const makeAuthenticationLive: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
|
|
23
|
+
export {};
|