@krak-stack/auth 0.1.32 → 0.1.34
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/components/auth-forms.js +7 -5
- package/dist/components/utils.js +21 -5
- package/dist/extra/schema.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/proxy.d.ts +1 -0
- package/dist/server/proxy.js +41 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
4
|
-
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
|
4
|
+
import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
|
|
5
5
|
import { REGEXP_ONLY_DIGITS } from "input-otp";
|
|
6
6
|
import { KeyRound, Mail } from "lucide-react";
|
|
7
7
|
import { useEffect, useState } from "react";
|
|
@@ -155,6 +155,8 @@ const useAuthProjectConfig = (baseUrl, searchString) => {
|
|
|
155
155
|
return result.value;
|
|
156
156
|
};
|
|
157
157
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
158
|
+
const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
|
|
159
|
+
const searchObject = (searchString) => Object.fromEntries(new URLSearchParams(searchString));
|
|
158
160
|
export function Signin(props) {
|
|
159
161
|
const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
|
|
160
162
|
const navigate = useNavigate();
|
|
@@ -342,7 +344,7 @@ export function Signin(props) {
|
|
|
342
344
|
event.preventDefault();
|
|
343
345
|
event.stopPropagation();
|
|
344
346
|
form.handleSubmit();
|
|
345
|
-
}, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", 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(
|
|
347
|
+
}, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", 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
|
|
346
348
|
? text(m.sign_in_email_otp_resend_countdown, {
|
|
347
349
|
seconds: String(emailOtpResendSeconds),
|
|
348
350
|
})
|
|
@@ -350,7 +352,7 @@ export function Signin(props) {
|
|
|
350
352
|
? m.sign_in_continue
|
|
351
353
|
: selectedAuthMethod === "emailOtp"
|
|
352
354
|
? m.sign_in_email_otp_verify
|
|
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(
|
|
355
|
+
: 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(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: m.auth_sign_up })] })) : null] })] }));
|
|
354
356
|
}
|
|
355
357
|
export function Signup(props) {
|
|
356
358
|
const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
|
|
@@ -428,13 +430,13 @@ export function Signup(props) {
|
|
|
428
430
|
}
|
|
429
431
|
};
|
|
430
432
|
if (!options.signUp) {
|
|
431
|
-
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_disabled_title }), _jsx(CardDescription, { children: m.sign_up_disabled_description })] }), _jsx(CardContent, { children: _jsxs("p", { className: "text-muted-foreground text-center text-sm", children: [m.sign_up_have_account, " ", _jsx(
|
|
433
|
+
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_disabled_title }), _jsx(CardDescription, { children: m.sign_up_disabled_description })] }), _jsx(CardContent, { children: _jsxs("p", { className: "text-muted-foreground text-center text-sm", children: [m.sign_up_have_account, " ", _jsx(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.auth_sign_in })] }) })] }));
|
|
432
434
|
}
|
|
433
435
|
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_title }), _jsx(CardDescription, { children: m.sign_up_description })] }), _jsxs(CardContent, { children: [_jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
434
436
|
event.preventDefault();
|
|
435
437
|
event.stopPropagation();
|
|
436
438
|
form.handleSubmit();
|
|
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(
|
|
439
|
+
}, 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(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.auth_sign_in })] })] })] }));
|
|
438
440
|
}
|
|
439
441
|
export function ResetPassword(props) {
|
|
440
442
|
const { authClient, labels: m } = useAuthFormOptions(props);
|
package/dist/components/utils.js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
export const isRecord = (value) => typeof value === "object" && value !== null;
|
|
2
|
+
const assetRoutePrefix = "/api/auth/assets/";
|
|
3
|
+
const legacyAssetRoutePrefix = "/api/assets/";
|
|
4
|
+
const assetKey = (value) => {
|
|
5
|
+
const path = value.trim();
|
|
6
|
+
if (path.startsWith(assetRoutePrefix))
|
|
7
|
+
return path.slice(assetRoutePrefix.length);
|
|
8
|
+
if (path.startsWith(legacyAssetRoutePrefix)) {
|
|
9
|
+
return path.slice(legacyAssetRoutePrefix.length);
|
|
10
|
+
}
|
|
11
|
+
if (path.startsWith("logos/"))
|
|
12
|
+
return path;
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
const assetRoute = (key) => `${assetRoutePrefix}${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
2
16
|
export const assetPath = (value) => {
|
|
3
17
|
if (!value?.trim())
|
|
4
18
|
return null;
|
|
5
19
|
try {
|
|
6
20
|
const url = new URL(value);
|
|
7
|
-
return url.pathname
|
|
21
|
+
return assetKey(url.pathname) ?? value;
|
|
8
22
|
}
|
|
9
23
|
catch {
|
|
10
|
-
return value;
|
|
24
|
+
return assetKey(value) ?? value;
|
|
11
25
|
}
|
|
12
26
|
};
|
|
13
27
|
export const assetUrl = (value, baseUrl) => {
|
|
14
28
|
const path = value?.trim();
|
|
15
29
|
if (!path)
|
|
16
30
|
return "";
|
|
17
|
-
|
|
31
|
+
const key = assetKey(path);
|
|
32
|
+
if (!key)
|
|
18
33
|
return path;
|
|
34
|
+
const route = assetRoute(key);
|
|
19
35
|
if (!baseUrl?.trim())
|
|
20
|
-
return
|
|
21
|
-
return new URL(
|
|
36
|
+
return route;
|
|
37
|
+
return new URL(route, baseUrl).toString();
|
|
22
38
|
};
|
package/dist/extra/schema.js
CHANGED
|
@@ -215,6 +215,11 @@ export const ExtraUploadedAsset = Schema.Struct({
|
|
|
215
215
|
identifier: "ExtraUploadedAsset",
|
|
216
216
|
title: "Extra uploaded asset",
|
|
217
217
|
description: "Stable public asset URL returned after an image upload.",
|
|
218
|
+
examples: [
|
|
219
|
+
{
|
|
220
|
+
url: "https://auth.example.com/api/auth/assets/logos/organizations/logo.png",
|
|
221
|
+
},
|
|
222
|
+
],
|
|
218
223
|
});
|
|
219
224
|
export class ExtraBadRequest extends Schema.ErrorClass("ExtraBadRequest")({
|
|
220
225
|
_tag: Schema.tag("ExtraBadRequest"),
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +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 { proxyAuthRequest } from "./server/proxy";
|
|
5
6
|
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
|
|
6
7
|
export * as BetterAuth from "./better-auth";
|
|
7
8
|
export * as Extra from "./extra";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +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 { proxyAuthRequest } from "./server/proxy";
|
|
5
6
|
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, } from "./components";
|
|
6
7
|
export * as BetterAuth from "./better-auth";
|
|
7
8
|
export * as Extra from "./extra";
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AuthService } from "../service";
|
|
2
2
|
export { AuthClientConfig } from "../config";
|
|
3
3
|
export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
|
|
4
|
+
export { proxyAuthRequest } from "./proxy";
|
|
4
5
|
export type { ServerActiveOrganization, ServerMembersResponse, ServerOrganizationsResponse, ServerUsersResponse, } from "./schema";
|
|
5
6
|
export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
|
package/dist/server/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL) => Promise<Response>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const blockedRequestHeaders = [
|
|
2
|
+
"connection",
|
|
3
|
+
"content-length",
|
|
4
|
+
"forwarded",
|
|
5
|
+
"host",
|
|
6
|
+
"keep-alive",
|
|
7
|
+
"proxy-authenticate",
|
|
8
|
+
"proxy-authorization",
|
|
9
|
+
"te",
|
|
10
|
+
"trailer",
|
|
11
|
+
"transfer-encoding",
|
|
12
|
+
"upgrade",
|
|
13
|
+
"cdn-loop",
|
|
14
|
+
];
|
|
15
|
+
const proxyHeaders = (request) => {
|
|
16
|
+
const headers = new Headers(request.headers);
|
|
17
|
+
for (const header of blockedRequestHeaders)
|
|
18
|
+
headers.delete(header);
|
|
19
|
+
for (const header of Array.from(headers.keys())) {
|
|
20
|
+
if (header.startsWith("cf-") || header.startsWith("x-forwarded-")) {
|
|
21
|
+
headers.delete(header);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
};
|
|
26
|
+
export const proxyAuthRequest = (request, baseUrl) => {
|
|
27
|
+
const target = new URL(request.url);
|
|
28
|
+
const authUrl = new URL(baseUrl);
|
|
29
|
+
const init = {
|
|
30
|
+
headers: proxyHeaders(request),
|
|
31
|
+
method: request.method,
|
|
32
|
+
};
|
|
33
|
+
target.protocol = authUrl.protocol;
|
|
34
|
+
target.host = authUrl.host;
|
|
35
|
+
target.username = authUrl.username;
|
|
36
|
+
target.password = authUrl.password;
|
|
37
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
38
|
+
init.body = request.body;
|
|
39
|
+
}
|
|
40
|
+
return fetch(new Request(target, init), { redirect: "manual" });
|
|
41
|
+
};
|