@krak-stack/auth 0.1.33 → 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.
@@ -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("a", { className: cn(buttonVariants({ variant: "link" }), "h-auto px-0"), href: `/forgot-password${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
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("a", { className: cn(buttonVariants({ variant: "link" }), "h-auto px-0"), href: `/sign-up${searchString}`, children: m.auth_sign_up })] })) : null] })] }));
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("a", { className: "text-foreground font-medium underline-offset-4 hover:underline", href: `/sign-in${searchString}`, children: m.auth_sign_in })] }) })] }));
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("a", { className: "text-foreground font-medium underline-offset-4 hover:underline", href: `/sign-in${searchString}`, children: m.auth_sign_in })] })] })] }));
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);
@@ -1,23 +1,38 @@
1
1
  export const isRecord = (value) => typeof value === "object" && value !== null;
2
- const isAssetPath = (path) => path.startsWith("/api/assets/") || path.startsWith("/api/auth/assets/");
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 isAssetPath(url.pathname) ? url.pathname : value;
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
- if (!isAssetPath(path))
31
+ const key = assetKey(path);
32
+ if (!key)
19
33
  return path;
34
+ const route = assetRoute(key);
20
35
  if (!baseUrl?.trim())
21
- return path;
22
- return new URL(path, baseUrl).toString();
36
+ return route;
37
+ return new URL(route, baseUrl).toString();
23
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [