@krak-stack/auth 0.1.30 → 0.1.32

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 CHANGED
@@ -31,7 +31,25 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
31
31
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
32
32
  readonly id: import("effect/Schema").String;
33
33
  readonly key: import("effect/Schema").String;
34
- }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("./extra").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
34
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("./extra").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
35
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
36
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
37
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
38
+ }>>, 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
+ readonly projectKey: import("effect/Schema").String;
40
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
41
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
42
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
43
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
44
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
45
+ readonly authOptions: import("effect/Schema").Struct<{
46
+ readonly emailPassword: import("effect/Schema").Boolean;
47
+ readonly emailOtp: import("effect/Schema").Boolean;
48
+ readonly google: import("effect/Schema").Boolean;
49
+ readonly signUp: import("effect/Schema").Boolean;
50
+ readonly signUpName: import("effect/Schema").Boolean;
51
+ }>;
52
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
35
53
  readonly newPassword: import("effect/Schema").NonEmptyString;
36
54
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
37
55
  readonly ok: import("effect/Schema").Boolean;
@@ -31,7 +31,25 @@ export declare const authApiClient: (baseUrl?: string | undefined) => AtomHttpAp
31
31
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
32
32
  readonly id: import("effect/Schema").String;
33
33
  readonly key: import("effect/Schema").String;
34
- }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("../extra").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
34
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("../extra").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
35
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
36
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
37
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
38
+ }>>, 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
+ readonly projectKey: import("effect/Schema").String;
40
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
41
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
42
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
43
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
44
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
45
+ readonly authOptions: import("effect/Schema").Struct<{
46
+ readonly emailPassword: import("effect/Schema").Boolean;
47
+ readonly emailOtp: import("effect/Schema").Boolean;
48
+ readonly google: import("effect/Schema").Boolean;
49
+ readonly signUp: import("effect/Schema").Boolean;
50
+ readonly signUpName: import("effect/Schema").Boolean;
51
+ }>;
52
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
35
53
  readonly newPassword: import("effect/Schema").NonEmptyString;
36
54
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
37
55
  readonly ok: import("effect/Schema").Boolean;
@@ -1,13 +1,12 @@
1
1
  import type { AuthUiClient } from "./auth-client";
2
- export declare function Signin({ authClient }: {
3
- authClient: AuthUiClient;
4
- }): import("react").JSX.Element;
5
- export declare function Signup({ authClient }: {
6
- authClient: AuthUiClient;
7
- }): import("react").JSX.Element;
8
- export declare function ResetPassword({ authClient }: {
9
- authClient: AuthUiClient;
10
- }): import("react").JSX.Element;
11
- export declare function TwoFactor({ authClient }: {
12
- authClient: AuthUiClient;
13
- }): import("react").JSX.Element;
2
+ import { type KrakstackAuthLocale } from "./auth-provider";
3
+ type AuthFormProps = {
4
+ authClient?: AuthUiClient;
5
+ baseUrl?: string | undefined;
6
+ locale?: KrakstackAuthLocale | undefined;
7
+ };
8
+ export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
9
+ export declare function Signup(props: AuthFormProps): import("react").JSX.Element;
10
+ export declare function ResetPassword(props: AuthFormProps): import("react").JSX.Element;
11
+ export declare function TwoFactor(props: AuthFormProps): import("react").JSX.Element;
12
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // @ts-nocheck
3
+ import { useAtomSuspense } from "@effect/atom-react";
3
4
  import { useNavigate, useRouterState } from "@tanstack/react-router";
4
5
  import { REGEXP_ONLY_DIGITS } from "input-otp";
5
6
  import { KeyRound, Mail } from "lucide-react";
@@ -10,7 +11,8 @@ import { Field, FieldLabel } from "@/components/ui/field";
10
11
  import { FieldError, useAppForm } from "@/components/ui/form";
11
12
  import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/components/ui/input-otp";
12
13
  import { cn } from "@/lib/utils";
13
- import { useAuthBrandingConfig } from "@/services/auth/client/branding";
14
+ import { authApiClient } from "./auth-api-client";
15
+ import { useKrakstackAuth } from "./auth-provider";
14
16
  const EMAIL_OTP_RESEND_COOLDOWN_SECONDS = 60;
15
17
  const defaultMessages = {
16
18
  en: {
@@ -116,27 +118,56 @@ const defaultMessages = {
116
118
  two_factor_verify_error: "Impossible de vérifier le code.",
117
119
  },
118
120
  };
119
- const labels = () => ({
120
- ...defaultMessages[currentLocale()],
121
+ const labels = (locale) => ({
122
+ ...defaultMessages[locale],
121
123
  });
122
- const currentLocale = () => typeof navigator !== "undefined" &&
123
- navigator.language.toLowerCase().startsWith("fr")
124
- ? "fr"
125
- : "en";
124
+ const useAuthFormOptions = ({ authClient, baseUrl, locale }) => {
125
+ const auth = useKrakstackAuth();
126
+ const resolvedAuthClient = authClient ?? auth?.authClient;
127
+ if (!resolvedAuthClient) {
128
+ throw new Error("Krakstack auth components require an authClient prop or KrakstackAuthProvider.");
129
+ }
130
+ return {
131
+ authClient: resolvedAuthClient,
132
+ baseUrl: baseUrl ?? auth?.baseUrl,
133
+ labels: labels(locale ?? auth?.locale ?? "en"),
134
+ };
135
+ };
136
+ const useAuthProjectConfig = (baseUrl, searchString) => {
137
+ const projectId = getSearchParam(searchString, "projectId");
138
+ const clientId = getSearchParam(searchString, "client_id");
139
+ const host = getBrowserAuthHost();
140
+ const result = useAtomSuspense(authApiClient(baseUrl).query("authExtra", "getProjectPublicConfig", {
141
+ query: {
142
+ ...(projectId ? { projectId } : {}),
143
+ ...(clientId ? { clientId } : {}),
144
+ ...(host ? { host } : {}),
145
+ },
146
+ timeToLive: "5 minutes",
147
+ reactivityKeys: [
148
+ "project-public-config",
149
+ ...(projectId ? [`project:${projectId}`] : []),
150
+ ...(clientId ? [`client:${clientId}`] : []),
151
+ ...(host ? [`host:${host}`] : []),
152
+ ],
153
+ serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}`,
154
+ }), { suspendOnWaiting: true });
155
+ return result.value;
156
+ };
126
157
  const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
127
- export function Signin({ authClient }) {
158
+ export function Signin(props) {
159
+ const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
128
160
  const navigate = useNavigate();
129
161
  const searchString = useRouterState({
130
162
  select: (state) => state.location.searchStr,
131
163
  });
132
- const projectConfig = useAuthBrandingConfig();
164
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString);
133
165
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
134
166
  const socialRedirectTarget = getSocialRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
135
167
  const oauthQuery = getOAuthQuery(searchString);
136
168
  const authOptions = projectConfig?.authOptions ?? {};
137
169
  const onNavigate = (target) => navigateTarget(target, navigate);
138
170
  const onTwoFactorRedirect = (href) => navigate({ href });
139
- const m = labels();
140
171
  const options = {
141
172
  emailPassword: authOptions.emailPassword ?? true,
142
173
  emailOtp: authOptions.emailOtp ?? true,
@@ -321,17 +352,17 @@ export function Signin({ authClient }) {
321
352
  ? m.sign_in_email_otp_verify
322
353
  : m.auth_sign_in }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsxs("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: [m.sign_in_need_account, " ", _jsx("a", { className: cn(buttonVariants({ variant: "link" }), "h-auto px-0"), href: `/sign-up${searchString}`, children: m.auth_sign_up })] })) : null] })] }));
323
354
  }
324
- export function Signup({ authClient }) {
355
+ export function Signup(props) {
356
+ const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
325
357
  const navigate = useNavigate();
326
358
  const searchString = useRouterState({
327
359
  select: (state) => state.location.searchStr,
328
360
  });
329
- const projectConfig = useAuthBrandingConfig();
361
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString);
330
362
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
331
363
  const authOptions = projectConfig?.authOptions ?? {};
332
364
  const onNavigate = (target) => navigate({ href: target });
333
365
  const onVerifyEmail = (email) => navigate({ to: "/verify-email", search: { email } });
334
- const m = labels();
335
366
  const options = {
336
367
  google: authOptions.google ?? true,
337
368
  signUp: authOptions.signUp ?? true,
@@ -405,14 +436,14 @@ export function Signup({ authClient }) {
405
436
  form.handleSubmit();
406
437
  }, children: [options.signUpName ? (_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.field_name, autoComplete: "name", required: true })) })) : null, _jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", required: true })) }), _jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "new-password", minLength: 8, required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }), options.google ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [_jsx(Divider, { label: m.auth_or_continue_with }), _jsxs(Button, { type: "button", variant: "outline", className: "w-full", onClick: signUpWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, _jsxs("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: [m.sign_up_have_account, " ", _jsx("a", { className: "text-foreground font-medium underline-offset-4 hover:underline", href: `/sign-in${searchString}`, children: m.auth_sign_in })] })] })] }));
407
438
  }
408
- export function ResetPassword({ authClient }) {
439
+ export function ResetPassword(props) {
440
+ const { authClient, labels: m } = useAuthFormOptions(props);
409
441
  const navigate = useNavigate();
410
442
  const searchString = useRouterState({
411
443
  select: (state) => state.location.searchStr,
412
444
  });
413
445
  const token = getSearchParam(searchString, "token") ?? "";
414
446
  const onSuccess = () => navigate({ to: "/sign-in" });
415
- const m = labels();
416
447
  const form = useAppForm({
417
448
  defaultValues: { password: "" },
418
449
  onSubmit: async ({ value, formApi }) => {
@@ -445,16 +476,16 @@ export function ResetPassword({ authClient }) {
445
476
  form.handleSubmit();
446
477
  }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.reset_password_new_password, type: "password", autoComplete: "new-password", minLength: 8, required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) })] }));
447
478
  }
448
- export function TwoFactor({ authClient }) {
479
+ export function TwoFactor(props) {
480
+ const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
449
481
  const navigate = useNavigate();
450
482
  const searchString = useRouterState({
451
483
  select: (state) => state.location.searchStr,
452
484
  });
453
- const projectConfig = useAuthBrandingConfig();
485
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString);
454
486
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
455
487
  const oauthQuery = getOAuthQuery(searchString);
456
488
  const onNavigate = (target) => navigateTarget(target, navigate);
457
- const m = labels();
458
489
  const [mode, setMode] = useState("totp");
459
490
  const [emailCodeSent, setEmailCodeSent] = useState(false);
460
491
  const form = useAppForm({
@@ -621,6 +652,7 @@ const normalizeAuthHost = (value) => {
621
652
  }
622
653
  };
623
654
  const getSearchParam = (searchString, key) => new URLSearchParams(searchString).get(key);
655
+ const getBrowserAuthHost = () => typeof window === "undefined" ? null : window.location.host;
624
656
  const navigateTarget = (target, navigate) => {
625
657
  if (shouldUseDocumentRedirect(target)) {
626
658
  navigate({ href: target });
@@ -0,0 +1,16 @@
1
+ import { type ReactNode } from "react";
2
+ import type { AuthUiClient } from "./auth-client";
3
+ export type KrakstackAuthLocale = "en" | "fr";
4
+ export type KrakstackAuthProviderProps = {
5
+ children: ReactNode;
6
+ locale?: KrakstackAuthLocale | undefined;
7
+ baseUrl?: string | undefined;
8
+ authClient?: AuthUiClient | undefined;
9
+ };
10
+ export type KrakstackAuthContextValue = {
11
+ locale: KrakstackAuthLocale;
12
+ baseUrl?: string | undefined;
13
+ authClient: AuthUiClient;
14
+ };
15
+ export declare function KrakstackAuthProvider({ children, locale, baseUrl, authClient, }: KrakstackAuthProviderProps): import("react").JSX.Element;
16
+ export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { apiKeyClient } from "@better-auth/api-key/client";
3
+ import { emailOTPClient, genericOAuthClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
4
+ import { createAuthClient } from "better-auth/react";
5
+ import { createContext, useContext, useMemo } from "react";
6
+ const KrakstackAuthContext = createContext(null);
7
+ const createAuthUiClient = (baseUrl) => createAuthClient({
8
+ ...(baseUrl ? { baseURL: baseUrl } : {}),
9
+ plugins: [
10
+ emailOTPClient(),
11
+ organizationClient(),
12
+ twoFactorClient(),
13
+ apiKeyClient(),
14
+ genericOAuthClient(),
15
+ ],
16
+ });
17
+ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, authClient, }) {
18
+ const resolvedAuthClient = useMemo(() => authClient ?? createAuthUiClient(baseUrl), [authClient, baseUrl]);
19
+ const value = useMemo(() => ({ authClient: resolvedAuthClient, baseUrl, locale }), [resolvedAuthClient, baseUrl, locale]);
20
+ return (_jsx(KrakstackAuthContext.Provider, { value: value, children: children }));
21
+ }
22
+ export const useKrakstackAuth = () => useContext(KrakstackAuthContext);
@@ -1,6 +1,8 @@
1
+ export { KrakstackAuthProvider, useKrakstackAuth } from "./auth-provider";
1
2
  export { OrganizationSwitcher } from "./organization-switcher";
2
3
  export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
3
4
  export { UserButton } from "./user-button";
5
+ export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
4
6
  export type { OrganizationSwitcherDialog } from "./organization-switcher";
5
7
  export type { UserButtonDialog } from "./user-button";
6
8
  export type { AuthUiClient } from "./auth-client";
@@ -1,3 +1,4 @@
1
+ export { KrakstackAuthProvider, useKrakstackAuth } from "./auth-provider";
1
2
  export { OrganizationSwitcher } from "./organization-switcher";
2
3
  export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
3
4
  export { UserButton } from "./user-button";
@@ -9,7 +9,25 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
9
9
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
10
10
  readonly id: import("effect/Schema").String;
11
11
  readonly key: import("effect/Schema").String;
12
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
12
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
13
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
14
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
15
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
16
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
17
+ readonly projectKey: import("effect/Schema").String;
18
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
19
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
20
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
21
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
22
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
23
+ readonly authOptions: import("effect/Schema").Struct<{
24
+ readonly emailPassword: import("effect/Schema").Boolean;
25
+ readonly emailOtp: import("effect/Schema").Boolean;
26
+ readonly google: import("effect/Schema").Boolean;
27
+ readonly signUp: import("effect/Schema").Boolean;
28
+ readonly signUpName: import("effect/Schema").Boolean;
29
+ }>;
30
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
13
31
  readonly newPassword: import("effect/Schema").NonEmptyString;
14
32
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
15
33
  readonly ok: import("effect/Schema").Boolean;
@@ -58,7 +76,25 @@ export declare const ExtraApi: HttpApi.HttpApi<"ExtraApi", HttpApiGroup.HttpApiG
58
76
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
59
77
  readonly id: import("effect/Schema").String;
60
78
  readonly key: import("effect/Schema").String;
61
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
79
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
80
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
81
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
82
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
83
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
84
+ readonly projectKey: import("effect/Schema").String;
85
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
86
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
87
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
88
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
89
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
90
+ readonly authOptions: import("effect/Schema").Struct<{
91
+ readonly emailPassword: import("effect/Schema").Boolean;
92
+ readonly emailOtp: import("effect/Schema").Boolean;
93
+ readonly google: import("effect/Schema").Boolean;
94
+ readonly signUp: import("effect/Schema").Boolean;
95
+ readonly signUpName: import("effect/Schema").Boolean;
96
+ }>;
97
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
62
98
  readonly newPassword: import("effect/Schema").NonEmptyString;
63
99
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
64
100
  readonly ok: import("effect/Schema").Boolean;
package/dist/extra/api.js CHANGED
@@ -1,7 +1,16 @@
1
1
  import { HttpApi, OpenApi } from "effect/unstable/httpapi";
2
2
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
- import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
3
+ import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
4
4
  export const ExtraApiGroup = HttpApiGroup.make("authExtra")
5
+ .add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
6
+ query: ExtraProjectPublicConfigQuery,
7
+ success: ExtraProjectPublicConfig,
8
+ error: [HttpApiError.InternalServerError],
9
+ }).annotateMerge(OpenApi.annotations({
10
+ title: "Get project public config",
11
+ summary: "Get host-aware project white-label config",
12
+ description: "Returns resolved public branding and authentication options through the proxied auth API.",
13
+ })))
5
14
  .add(HttpApiEndpoint.post("setPassword", "/auth/set-password", {
6
15
  payload: ExtraSetPasswordPayload,
7
16
  success: ExtraOkResponse,
@@ -7,7 +7,25 @@ declare const ExtraApiClient_base: AtomHttpApi.AtomHttpApiClient<ExtraApiClient,
7
7
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
8
8
  readonly id: import("effect/Schema").String;
9
9
  readonly key: import("effect/Schema").String;
10
- }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("./schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
10
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("./schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
11
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
12
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
13
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
14
+ }>>, 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
+ readonly projectKey: import("effect/Schema").String;
16
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
17
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
18
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
19
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
20
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
21
+ readonly authOptions: import("effect/Schema").Struct<{
22
+ readonly emailPassword: import("effect/Schema").Boolean;
23
+ readonly emailOtp: import("effect/Schema").Boolean;
24
+ readonly google: import("effect/Schema").Boolean;
25
+ readonly signUp: import("effect/Schema").Boolean;
26
+ readonly signUpName: import("effect/Schema").Boolean;
27
+ }>;
28
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
11
29
  readonly newPassword: import("effect/Schema").NonEmptyString;
12
30
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
13
31
  readonly ok: import("effect/Schema").Boolean;
@@ -69,6 +69,33 @@ export declare const ExtraVerifyApiKeyResponse: Schema.Struct<{
69
69
  readonly metadata: Schema.NullOr<Schema.Unknown>;
70
70
  }>>;
71
71
  }>;
72
+ export declare const ExtraProjectPublicConfigQuery: Schema.Struct<{
73
+ readonly projectId: Schema.optional<Schema.String>;
74
+ readonly clientId: Schema.optional<Schema.String>;
75
+ readonly host: Schema.optional<Schema.String>;
76
+ }>;
77
+ export declare const ExtraProjectAuthOptions: Schema.Struct<{
78
+ readonly emailPassword: Schema.Boolean;
79
+ readonly emailOtp: Schema.Boolean;
80
+ readonly google: Schema.Boolean;
81
+ readonly signUp: Schema.Boolean;
82
+ readonly signUpName: Schema.Boolean;
83
+ }>;
84
+ export declare const ExtraProjectPublicConfig: Schema.Struct<{
85
+ readonly projectKey: Schema.String;
86
+ readonly name: Schema.NullOr<Schema.String>;
87
+ readonly logoUrl: Schema.NullOr<Schema.String>;
88
+ readonly authDomain: Schema.NullOr<Schema.String>;
89
+ readonly rootDomain: Schema.NullOr<Schema.String>;
90
+ readonly themeCss: Schema.NullOr<Schema.String>;
91
+ readonly authOptions: Schema.Struct<{
92
+ readonly emailPassword: Schema.Boolean;
93
+ readonly emailOtp: Schema.Boolean;
94
+ readonly google: Schema.Boolean;
95
+ readonly signUp: Schema.Boolean;
96
+ readonly signUpName: Schema.Boolean;
97
+ }>;
98
+ }>;
72
99
  export declare const ExtraOkResponse: Schema.Struct<{
73
100
  readonly ok: Schema.Boolean;
74
101
  }>;
@@ -89,5 +116,7 @@ export type ExtraCreateApiKeyPayload = typeof ExtraCreateApiKeyPayload.Type;
89
116
  export type ExtraCreateApiKeyResponse = typeof ExtraCreateApiKeyResponse.Type;
90
117
  export type ExtraVerifyApiKeyPayload = typeof ExtraVerifyApiKeyPayload.Type;
91
118
  export type ExtraVerifyApiKeyResponse = typeof ExtraVerifyApiKeyResponse.Type;
119
+ export type ExtraProjectPublicConfigQuery = typeof ExtraProjectPublicConfigQuery.Type;
120
+ export type ExtraProjectPublicConfig = typeof ExtraProjectPublicConfig.Type;
92
121
  export type ExtraOkResponse = typeof ExtraOkResponse.Type;
93
122
  export {};
@@ -135,6 +135,72 @@ export const ExtraVerifyApiKeyResponse = Schema.Struct({
135
135
  title: "Extra verify API key response",
136
136
  description: "Result of verifying a remote API key.",
137
137
  });
138
+ export const ExtraProjectPublicConfigQuery = Schema.Struct({
139
+ projectId: Schema.optional(Schema.String),
140
+ clientId: Schema.optional(Schema.String),
141
+ host: Schema.optional(Schema.String),
142
+ }).annotate({
143
+ identifier: "ExtraProjectPublicConfigQuery",
144
+ title: "Extra project public config query",
145
+ description: "Optional project ID, auth host, and OAuth client ID used to resolve public project branding through the proxied auth API.",
146
+ examples: [
147
+ {
148
+ projectId: "project-id",
149
+ host: "auth.example.com",
150
+ clientId: "oauth-client-id",
151
+ },
152
+ ],
153
+ });
154
+ export const ExtraProjectAuthOptions = Schema.Struct({
155
+ emailPassword: Schema.Boolean,
156
+ emailOtp: Schema.Boolean,
157
+ google: Schema.Boolean,
158
+ signUp: Schema.Boolean,
159
+ signUpName: Schema.Boolean,
160
+ }).annotate({
161
+ identifier: "ExtraProjectAuthOptions",
162
+ title: "Extra project authentication options",
163
+ description: "Resolved authentication methods visible for auth pages.",
164
+ examples: [
165
+ {
166
+ emailPassword: true,
167
+ emailOtp: true,
168
+ google: true,
169
+ signUp: true,
170
+ signUpName: true,
171
+ },
172
+ ],
173
+ });
174
+ export const ExtraProjectPublicConfig = Schema.Struct({
175
+ projectKey: Schema.String,
176
+ name: Schema.NullOr(Schema.String),
177
+ logoUrl: Schema.NullOr(Schema.String),
178
+ authDomain: Schema.NullOr(Schema.String),
179
+ rootDomain: Schema.NullOr(Schema.String),
180
+ themeCss: Schema.NullOr(Schema.String),
181
+ authOptions: ExtraProjectAuthOptions,
182
+ }).annotate({
183
+ identifier: "ExtraProjectPublicConfig",
184
+ title: "Extra project public config",
185
+ description: "Public white-label configuration used by auth pages for a project.",
186
+ examples: [
187
+ {
188
+ projectKey: "auth.example.com",
189
+ name: "Example project",
190
+ logoUrl: "https://example.com/logo.svg",
191
+ authDomain: "auth.example.com",
192
+ rootDomain: "example.com",
193
+ themeCss: '[data-project-theme="auth.example.com"] { --primary: oklch(0.5 0.1 240); }',
194
+ authOptions: {
195
+ emailPassword: true,
196
+ emailOtp: true,
197
+ google: true,
198
+ signUp: false,
199
+ signUpName: true,
200
+ },
201
+ },
202
+ ],
203
+ });
138
204
  export const ExtraOkResponse = Schema.Struct({
139
205
  ok: Schema.Boolean,
140
206
  }).annotate({
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from "./schema";
2
2
  export { AuthApi } from "./api";
3
3
  export { AuthService, type AuthServiceLayerOptions } from "./service";
4
4
  export { AuthClientConfig } from "./config";
5
- export { OrganizationSwitcher, ResetPassword, Signin, Signup, TwoFactor, UserButton, type AuthUiClient, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
5
+ export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
6
6
  export * as BetterAuth from "./better-auth";
7
7
  export * as Extra from "./extra";
8
8
  export * as Server from "./server";
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export * from "./schema";
2
2
  export { AuthApi } from "./api";
3
3
  export { AuthService } from "./service";
4
4
  export { AuthClientConfig } from "./config";
5
- export { OrganizationSwitcher, ResetPassword, Signin, Signup, TwoFactor, UserButton, } from "./components";
5
+ export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, } from "./components";
6
6
  export * as BetterAuth from "./better-auth";
7
7
  export * as Extra from "./extra";
8
8
  export * as Server from "./server";
package/dist/service.d.ts CHANGED
@@ -48,6 +48,28 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
48
48
  readonly id: string;
49
49
  readonly key: string;
50
50
  }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra").ExtraBadRequest | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
51
+ readonly getProjectPublicConfig: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
52
+ readonly query: {
53
+ readonly projectId?: string | undefined;
54
+ readonly clientId?: string | undefined;
55
+ readonly host?: string | undefined;
56
+ };
57
+ readonly responseMode?: Mode;
58
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
59
+ readonly projectKey: string;
60
+ readonly name: string | null;
61
+ readonly logoUrl: string | null;
62
+ readonly authDomain: string | null;
63
+ readonly rootDomain: string | null;
64
+ readonly themeCss: string | null;
65
+ readonly authOptions: {
66
+ readonly emailPassword: boolean;
67
+ readonly emailOtp: boolean;
68
+ readonly google: boolean;
69
+ readonly signUp: boolean;
70
+ readonly signUpName: boolean;
71
+ };
72
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/unstable/httpapi/HttpApiError").InternalServerError | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
51
73
  readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
52
74
  readonly payload: {
53
75
  readonly newPassword: string;
@@ -381,6 +403,28 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
381
403
  readonly id: string;
382
404
  readonly key: string;
383
405
  }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra").ExtraBadRequest | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
406
+ readonly getProjectPublicConfig: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
407
+ readonly query: {
408
+ readonly projectId?: string | undefined;
409
+ readonly clientId?: string | undefined;
410
+ readonly host?: string | undefined;
411
+ };
412
+ readonly responseMode?: Mode;
413
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
414
+ readonly projectKey: string;
415
+ readonly name: string | null;
416
+ readonly logoUrl: string | null;
417
+ readonly authDomain: string | null;
418
+ readonly rootDomain: string | null;
419
+ readonly themeCss: string | null;
420
+ readonly authOptions: {
421
+ readonly emailPassword: boolean;
422
+ readonly emailOtp: boolean;
423
+ readonly google: boolean;
424
+ readonly signUp: boolean;
425
+ readonly signUpName: boolean;
426
+ };
427
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/unstable/httpapi/HttpApiError").InternalServerError | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
384
428
  readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
385
429
  readonly payload: {
386
430
  readonly newPassword: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [