@krak-stack/auth 0.1.33 → 0.1.35
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.
|
@@ -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,23 +1,38 @@
|
|
|
1
1
|
export const isRecord = (value) => typeof value === "object" && value !== null;
|
|
2
|
-
const
|
|
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("/")}`;
|
|
3
16
|
export const assetPath = (value) => {
|
|
4
17
|
if (!value?.trim())
|
|
5
18
|
return null;
|
|
6
19
|
try {
|
|
7
20
|
const url = new URL(value);
|
|
8
|
-
return
|
|
21
|
+
return assetKey(url.pathname) ?? value;
|
|
9
22
|
}
|
|
10
23
|
catch {
|
|
11
|
-
return value;
|
|
24
|
+
return assetKey(value) ?? value;
|
|
12
25
|
}
|
|
13
26
|
};
|
|
14
27
|
export const assetUrl = (value, baseUrl) => {
|
|
15
28
|
const path = value?.trim();
|
|
16
29
|
if (!path)
|
|
17
30
|
return "";
|
|
18
|
-
|
|
31
|
+
const key = assetKey(path);
|
|
32
|
+
if (!key)
|
|
19
33
|
return path;
|
|
34
|
+
const route = assetRoute(key);
|
|
20
35
|
if (!baseUrl?.trim())
|
|
21
|
-
return
|
|
22
|
-
return new URL(
|
|
36
|
+
return route;
|
|
37
|
+
return new URL(route, baseUrl).toString();
|
|
23
38
|
};
|
package/dist/server/proxy.js
CHANGED
|
@@ -14,6 +14,7 @@ const blockedRequestHeaders = [
|
|
|
14
14
|
];
|
|
15
15
|
const proxyHeaders = (request) => {
|
|
16
16
|
const headers = new Headers(request.headers);
|
|
17
|
+
const url = new URL(request.url);
|
|
17
18
|
for (const header of blockedRequestHeaders)
|
|
18
19
|
headers.delete(header);
|
|
19
20
|
for (const header of Array.from(headers.keys())) {
|
|
@@ -21,6 +22,8 @@ const proxyHeaders = (request) => {
|
|
|
21
22
|
headers.delete(header);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
headers.set("x-forwarded-host", url.host);
|
|
26
|
+
headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
|
|
24
27
|
return headers;
|
|
25
28
|
};
|
|
26
29
|
export const proxyAuthRequest = (request, baseUrl) => {
|
package/dist/server/schema.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ export declare const ServerCreateDomainPayload: Schema.Struct<{
|
|
|
94
94
|
readonly managed: Schema.Boolean;
|
|
95
95
|
}>;
|
|
96
96
|
export declare const ServerUpdateDomainPayload: Schema.Struct<{
|
|
97
|
+
readonly hostname: Schema.NonEmptyString;
|
|
97
98
|
readonly rootHostname: Schema.NonEmptyString;
|
|
98
99
|
readonly projectId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
99
100
|
readonly organizationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
package/dist/server/schema.js
CHANGED
|
@@ -130,6 +130,7 @@ export const ServerCreateDomainPayload = Schema.Struct({
|
|
|
130
130
|
],
|
|
131
131
|
});
|
|
132
132
|
export const ServerUpdateDomainPayload = Schema.Struct({
|
|
133
|
+
hostname: Schema.NonEmptyString,
|
|
133
134
|
rootHostname: Schema.NonEmptyString,
|
|
134
135
|
projectId: Schema.optional(Schema.NullOr(Schema.String)),
|
|
135
136
|
organizationId: Schema.optional(Schema.NullOr(Schema.String)),
|
|
@@ -140,6 +141,7 @@ export const ServerUpdateDomainPayload = Schema.Struct({
|
|
|
140
141
|
description: "Payload used by administrators to update an auth hostname's trust target, ownership links, and Cloudflare management mode.",
|
|
141
142
|
examples: [
|
|
142
143
|
{
|
|
144
|
+
hostname: "auth.institute.example.com",
|
|
143
145
|
rootHostname: "institute.example.com",
|
|
144
146
|
projectId: "kokobi",
|
|
145
147
|
organizationId: "org_1",
|