@mesob/auth-react 0.1.1 → 0.2.1
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/auth-card.js +1 -1
- package/dist/components/auth/auth-card.js.map +1 -1
- package/dist/components/auth/{auth-page-layout.d.ts → auth-layout.d.ts} +3 -3
- package/dist/components/auth/{auth-page-layout.js → auth-layout.js} +4 -4
- package/dist/components/auth/auth-layout.js.map +1 -0
- package/dist/components/auth/countdown.js +15 -6
- package/dist/components/auth/countdown.js.map +1 -1
- package/dist/components/auth/forgot-password.d.ts +1 -9
- package/dist/components/auth/forgot-password.js +267 -43
- package/dist/components/auth/forgot-password.js.map +1 -1
- package/dist/components/auth/reset-password-form.d.ts +2 -10
- package/dist/components/auth/reset-password-form.js +366 -118
- package/dist/components/auth/reset-password-form.js.map +1 -1
- package/dist/components/auth/sign-in.d.ts +2 -10
- package/dist/components/auth/sign-in.js +358 -130
- package/dist/components/auth/sign-in.js.map +1 -1
- package/dist/components/auth/sign-up.d.ts +2 -10
- package/dist/components/auth/sign-up.js +379 -131
- package/dist/components/auth/sign-up.js.map +1 -1
- package/dist/components/auth/verification-form.d.ts +2 -16
- package/dist/components/auth/verification-form.js +15 -6
- package/dist/components/auth/verification-form.js.map +1 -1
- package/dist/components/auth/verify-email.d.ts +10 -0
- package/dist/components/auth/{pages/verify-email-page.js → verify-email.js} +54 -34
- package/dist/components/auth/verify-email.js.map +1 -0
- package/dist/components/auth/verify-phone.d.ts +11 -0
- package/dist/components/auth/{pages/verify-phone-page.js → verify-phone.js} +53 -46
- package/dist/components/auth/verify-phone.js.map +1 -0
- package/dist/components/iam/permissions.d.ts +5 -0
- package/dist/components/iam/{permissions/permissions-page.js → permissions.js} +29 -13
- package/dist/components/iam/permissions.js.map +1 -0
- package/dist/components/iam/roles.d.ts +5 -0
- package/dist/components/iam/{roles/roles-page.js → roles.js} +29 -13
- package/dist/components/iam/roles.js.map +1 -0
- package/dist/components/iam/sessions.d.ts +5 -0
- package/dist/components/iam/{sessions/sessions-page.js → sessions.js} +13 -11
- package/dist/components/iam/sessions.js.map +1 -0
- package/dist/components/iam/tenants.d.ts +5 -0
- package/dist/components/iam/{tenants/tenants-page.js → tenants.js} +13 -11
- package/dist/components/iam/tenants.js.map +1 -0
- package/dist/components/iam/users.d.ts +5 -0
- package/dist/components/iam/{users/users-page.js → users.js} +13 -11
- package/dist/components/iam/users.js.map +1 -0
- package/dist/components/profile/account.d.ts +5 -0
- package/dist/components/profile/account.js +66 -0
- package/dist/components/profile/account.js.map +1 -0
- package/dist/components/profile/change-email-form.d.ts +5 -0
- package/dist/components/profile/change-email-form.js +721 -0
- package/dist/components/profile/change-email-form.js.map +1 -0
- package/dist/components/profile/change-password-form.d.ts +5 -0
- package/dist/components/profile/change-password-form.js +256 -0
- package/dist/components/profile/change-password-form.js.map +1 -0
- package/dist/components/profile/change-phone-form.d.ts +5 -0
- package/dist/components/profile/change-phone-form.js +758 -0
- package/dist/components/profile/change-phone-form.js.map +1 -0
- package/dist/components/profile/change-profile.d.ts +9 -0
- package/dist/components/profile/change-profile.js +37 -0
- package/dist/components/profile/change-profile.js.map +1 -0
- package/dist/components/profile/otp-verification-modal.d.ts +15 -0
- package/dist/components/profile/otp-verification-modal.js +261 -0
- package/dist/components/profile/otp-verification-modal.js.map +1 -0
- package/dist/components/profile/request-change-email-form.d.ts +10 -0
- package/dist/components/profile/request-change-email-form.js +293 -0
- package/dist/components/profile/request-change-email-form.js.map +1 -0
- package/dist/components/profile/request-change-phone-form.d.ts +10 -0
- package/dist/components/profile/request-change-phone-form.js +331 -0
- package/dist/components/profile/request-change-phone-form.js.map +1 -0
- package/dist/components/profile/security.d.ts +5 -0
- package/dist/components/profile/security.js +1439 -0
- package/dist/components/profile/security.js.map +1 -0
- package/dist/components/profile/verify-change-email-form.d.ts +11 -0
- package/dist/components/profile/verify-change-email-form.js +402 -0
- package/dist/components/profile/verify-change-email-form.js.map +1 -0
- package/dist/components/profile/verify-change-phone-form.d.ts +11 -0
- package/dist/components/profile/verify-change-phone-form.js +406 -0
- package/dist/components/profile/verify-change-phone-form.js.map +1 -0
- package/dist/components/shared/{data-table/data-table.js → data-table.js} +2 -2
- package/dist/components/shared/data-table.js.map +1 -0
- package/dist/index.d.ts +42 -93
- package/dist/index.js +2298 -1300
- package/dist/index.js.map +1 -1
- package/dist/types-D3s9oE-5.d.ts +75 -0
- package/dist/verification-form-ipSRTtQB.d.ts +22 -0
- package/package.json +3 -2
- package/dist/components/auth/auth-page-layout.js.map +0 -1
- package/dist/components/auth/pages/forgot-password-page.d.ts +0 -6
- package/dist/components/auth/pages/forgot-password-page.js +0 -362
- package/dist/components/auth/pages/forgot-password-page.js.map +0 -1
- package/dist/components/auth/pages/reset-password-page.d.ts +0 -9
- package/dist/components/auth/pages/reset-password-page.js +0 -514
- package/dist/components/auth/pages/reset-password-page.js.map +0 -1
- package/dist/components/auth/pages/sign-in-page.d.ts +0 -8
- package/dist/components/auth/pages/sign-in-page.js +0 -565
- package/dist/components/auth/pages/sign-in-page.js.map +0 -1
- package/dist/components/auth/pages/sign-up-page.d.ts +0 -9
- package/dist/components/auth/pages/sign-up-page.js +0 -518
- package/dist/components/auth/pages/sign-up-page.js.map +0 -1
- package/dist/components/auth/pages/verify-email-page.d.ts +0 -10
- package/dist/components/auth/pages/verify-email-page.js.map +0 -1
- package/dist/components/auth/pages/verify-phone-page.d.ts +0 -11
- package/dist/components/auth/pages/verify-phone-page.js.map +0 -1
- package/dist/components/iam/permissions/permissions-page.d.ts +0 -5
- package/dist/components/iam/permissions/permissions-page.js.map +0 -1
- package/dist/components/iam/roles/roles-page.d.ts +0 -5
- package/dist/components/iam/roles/roles-page.js.map +0 -1
- package/dist/components/iam/sessions/sessions-page.d.ts +0 -5
- package/dist/components/iam/sessions/sessions-page.js.map +0 -1
- package/dist/components/iam/tenants/tenants-page.d.ts +0 -5
- package/dist/components/iam/tenants/tenants-page.js.map +0 -1
- package/dist/components/iam/users/users-page.d.ts +0 -5
- package/dist/components/iam/users/users-page.js.map +0 -1
- package/dist/components/profile/profile-page.d.ts +0 -8
- package/dist/components/profile/profile-page.js +0 -163
- package/dist/components/profile/profile-page.js.map +0 -1
- package/dist/components/shared/data-table/data-table.js.map +0 -1
- package/dist/handle-error-BqDMxnQZ.d.ts +0 -8
- /package/dist/components/shared/{data-table/data-table.d.ts → data-table.d.ts} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
type UIConfig = {
|
|
2
|
+
logo: React.ReactNode;
|
|
3
|
+
name: React.ReactNode;
|
|
4
|
+
logoImage?: string;
|
|
5
|
+
};
|
|
6
|
+
type FeaturesConfig = {
|
|
7
|
+
enableSignup?: boolean;
|
|
8
|
+
enablePasswordReset?: boolean;
|
|
9
|
+
enableEmailSignup?: boolean;
|
|
10
|
+
enablePhoneSignup?: boolean;
|
|
11
|
+
enableSocialSignup?: boolean;
|
|
12
|
+
socialProviders?: string[];
|
|
13
|
+
};
|
|
14
|
+
type TenantConfig = {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
};
|
|
18
|
+
type NavigationConfig = {
|
|
19
|
+
locale?: string;
|
|
20
|
+
defaultRedirectUrl?: string;
|
|
21
|
+
onNavigate?: (path: string) => void;
|
|
22
|
+
linkComponent?: React.ComponentType<React.ComponentProps<'a'> & {
|
|
23
|
+
href: string;
|
|
24
|
+
}>;
|
|
25
|
+
links?: {
|
|
26
|
+
signIn?: string;
|
|
27
|
+
signUp?: string;
|
|
28
|
+
forgotPassword?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type AuthClientConfig = {
|
|
32
|
+
baseURL: string;
|
|
33
|
+
ui: UIConfig;
|
|
34
|
+
features?: FeaturesConfig;
|
|
35
|
+
tenant?: TenantConfig;
|
|
36
|
+
navigation?: NavigationConfig;
|
|
37
|
+
messages?: Record<string, unknown>;
|
|
38
|
+
cookiePrefix?: string;
|
|
39
|
+
phoneRegex?: RegExp | string;
|
|
40
|
+
};
|
|
41
|
+
type UserRole = {
|
|
42
|
+
id: string;
|
|
43
|
+
roleId: string;
|
|
44
|
+
code: string;
|
|
45
|
+
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
type User = {
|
|
49
|
+
id: string;
|
|
50
|
+
tenantId: string;
|
|
51
|
+
fullName: string;
|
|
52
|
+
email: string | null;
|
|
53
|
+
phone: string | null;
|
|
54
|
+
handle: string;
|
|
55
|
+
image: string | null;
|
|
56
|
+
emailVerified: boolean;
|
|
57
|
+
phoneVerified: boolean;
|
|
58
|
+
lastSignInAt: string | null;
|
|
59
|
+
userRoles?: UserRole[];
|
|
60
|
+
};
|
|
61
|
+
type Session = {
|
|
62
|
+
id: string;
|
|
63
|
+
expiresAt: string;
|
|
64
|
+
createdAt?: string;
|
|
65
|
+
userAgent: string | null;
|
|
66
|
+
ip: string | null;
|
|
67
|
+
};
|
|
68
|
+
type AuthResponse = {
|
|
69
|
+
user: User;
|
|
70
|
+
session: Session;
|
|
71
|
+
sessionToken: string;
|
|
72
|
+
sessionExpiresAt: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type { AuthClientConfig as A, Session as S, User as U, AuthResponse as a, UserRole as b };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type AuthErrorContent = {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
type TranslatorFunction = (key: string, params?: Record<string, string | number>) => string;
|
|
8
|
+
declare const handleError: (err: unknown, setError: (error: AuthErrorContent | null) => void, t: TranslatorFunction) => void;
|
|
9
|
+
|
|
10
|
+
type VerificationFormValues = {
|
|
11
|
+
code: string;
|
|
12
|
+
};
|
|
13
|
+
type VerificationFormProps = {
|
|
14
|
+
verificationId: string;
|
|
15
|
+
onSubmit: (values: VerificationFormValues) => Promise<void> | void;
|
|
16
|
+
onResend: () => Promise<void> | void;
|
|
17
|
+
isLoading?: boolean;
|
|
18
|
+
error?: AuthErrorContent | string | null;
|
|
19
|
+
};
|
|
20
|
+
declare const VerificationForm: ({ onSubmit, onResend, isLoading, }: VerificationFormProps) => react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { type AuthErrorContent as A, VerificationForm as V, handleError as h };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mesob/auth-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
"openapi-fetch": "^0.15.0",
|
|
26
26
|
"openapi-react-query": "^0.5.1",
|
|
27
27
|
"react-hook-form": "^7.66.1",
|
|
28
|
+
"sonner": "^2.0.7",
|
|
28
29
|
"zod": "^4.1.12",
|
|
29
|
-
"@mesob/ui": "0.
|
|
30
|
+
"@mesob/ui": "0.2.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/react": "^19",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/auth/auth-page-layout.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\ntype AuthPageLayoutProps = {\n title: string;\n description?: string;\n children: ReactNode;\n footer?: ReactNode;\n logoImage?: string;\n};\n\nexport const AuthPageLayout = ({\n title,\n description,\n children,\n footer,\n logoImage,\n}: AuthPageLayoutProps) => {\n return (\n <div className=\"space-y-4\">\n <div className=\"flex size-8 mb-6 w-full items-center justify-center rounded-md\">\n {/** biome-ignore lint/performance/noImgElement: logo image */}\n <img src={logoImage || ''} alt=\"Mesob\" width={42} height={42} />\n </div>\n <div className=\"text-center\">\n <h1 className=\"text-2xl font-bold tracking-tight\">{title}</h1>\n {description && (\n <p className=\"mt-2 text-sm text-muted-foreground\">{description}</p>\n )}\n </div>\n\n {children}\n\n <div className=\"mt-2 w-full\">\n {footer && (\n <div className=\"w-full text-center text-sm text-muted-foreground\">\n {footer}\n </div>\n )}\n </div>\n </div>\n );\n};\n"],"mappings":";;;AAuBQ,cAEF,YAFE;AAXD,IAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA2B;AACzB,SACE,qBAAC,SAAI,WAAU,aACb;AAAA,wBAAC,SAAI,WAAU,kEAEb,8BAAC,SAAI,KAAK,aAAa,IAAI,KAAI,SAAQ,OAAO,IAAI,QAAQ,IAAI,GAChE;AAAA,IACA,qBAAC,SAAI,WAAU,eACb;AAAA,0BAAC,QAAG,WAAU,qCAAqC,iBAAM;AAAA,MACxD,eACC,oBAAC,OAAE,WAAU,sCAAsC,uBAAY;AAAA,OAEnE;AAAA,IAEC;AAAA,IAED,oBAAC,SAAI,WAAU,eACZ,oBACC,oBAAC,SAAI,WAAU,oDACZ,kBACH,GAEJ;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/components/auth/pages/forgot-password-page.tsx
|
|
4
|
-
import {
|
|
5
|
-
Alert,
|
|
6
|
-
AlertDescription,
|
|
7
|
-
AlertTitle
|
|
8
|
-
} from "@mesob/ui/components/alert";
|
|
9
|
-
import { toast } from "@mesob/ui/components/sonner";
|
|
10
|
-
import { IconAlertCircle } from "@tabler/icons-react";
|
|
11
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
12
|
-
|
|
13
|
-
// src/lib/translations.ts
|
|
14
|
-
function createTranslator(messages, namespace) {
|
|
15
|
-
return (key, params) => {
|
|
16
|
-
const fullKey = namespace ? `${namespace}.${key}` : key;
|
|
17
|
-
const keys = fullKey.split(".");
|
|
18
|
-
let value = messages;
|
|
19
|
-
for (const k of keys) {
|
|
20
|
-
if (value && typeof value === "object" && value !== null) {
|
|
21
|
-
value = value[k];
|
|
22
|
-
} else {
|
|
23
|
-
return fullKey;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (typeof value !== "string") {
|
|
27
|
-
return fullKey;
|
|
28
|
-
}
|
|
29
|
-
if (params) {
|
|
30
|
-
return value.replace(
|
|
31
|
-
/\{(\w+)\}/g,
|
|
32
|
-
(_, param) => String(params[param] ?? `{${param}}`)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// src/provider.tsx
|
|
40
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
41
|
-
import { deepmerge } from "deepmerge-ts";
|
|
42
|
-
import createFetchClient from "openapi-fetch";
|
|
43
|
-
import createClient from "openapi-react-query";
|
|
44
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
45
|
-
import { jsx } from "react/jsx-runtime";
|
|
46
|
-
var SessionContext = createContext(null);
|
|
47
|
-
var ApiContext = createContext(null);
|
|
48
|
-
var ConfigContext = createContext(null);
|
|
49
|
-
var queryClient = new QueryClient({
|
|
50
|
-
defaultOptions: {
|
|
51
|
-
queries: {
|
|
52
|
-
staleTime: 1e3 * 60 * 5,
|
|
53
|
-
gcTime: 1e3 * 60 * 10,
|
|
54
|
-
retry: 1,
|
|
55
|
-
refetchOnWindowFocus: false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
function useApi() {
|
|
60
|
-
const context = useContext(ApiContext);
|
|
61
|
-
if (!context) {
|
|
62
|
-
throw new Error("useApi must be used within MesobAuthProvider");
|
|
63
|
-
}
|
|
64
|
-
return context;
|
|
65
|
-
}
|
|
66
|
-
function useConfig() {
|
|
67
|
-
const context = useContext(ConfigContext);
|
|
68
|
-
if (!context) {
|
|
69
|
-
throw new Error("useConfig must be used within MesobAuthProvider");
|
|
70
|
-
}
|
|
71
|
-
return context;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// src/constants/auth.error.codes.ts
|
|
75
|
-
var AUTH_ERROR_MAPPING = {
|
|
76
|
-
USER_NOT_FOUND: {
|
|
77
|
-
title: "Account Not Found",
|
|
78
|
-
description: "We could not find an account with that identifier. Please check your spelling or sign up."
|
|
79
|
-
},
|
|
80
|
-
INVALID_PASSWORD: {
|
|
81
|
-
title: "Invalid Password",
|
|
82
|
-
description: "The password you entered is incorrect. Please try again."
|
|
83
|
-
},
|
|
84
|
-
USER_EXISTS: {
|
|
85
|
-
title: "Account Already Exists",
|
|
86
|
-
description: "An account with this identifier already exists. Please sign in instead."
|
|
87
|
-
},
|
|
88
|
-
VERIFICATION_EXPIRED: {
|
|
89
|
-
title: "Verification Expired",
|
|
90
|
-
description: "The verification code or link has expired. Please request a new one."
|
|
91
|
-
},
|
|
92
|
-
VERIFICATION_MISMATCH: {
|
|
93
|
-
title: "Invalid Code",
|
|
94
|
-
description: "The verification code you entered is invalid. Please double-check and try again."
|
|
95
|
-
},
|
|
96
|
-
VERIFICATION_NOT_FOUND: {
|
|
97
|
-
title: "Verification Not Found",
|
|
98
|
-
description: "We could not find a pending verification request. Please restart the process."
|
|
99
|
-
},
|
|
100
|
-
TOO_MANY_ATTEMPTS: {
|
|
101
|
-
title: "Too Many Attempts",
|
|
102
|
-
description: "You have made too many requests recently. Please wait a moment before trying again."
|
|
103
|
-
},
|
|
104
|
-
REQUIRES_VERIFICATION: {
|
|
105
|
-
title: "Verification Required",
|
|
106
|
-
description: "You need to verify your account before you can continue. Please check your email or phone."
|
|
107
|
-
},
|
|
108
|
-
UNAUTHORIZED: {
|
|
109
|
-
title: "Unauthorized",
|
|
110
|
-
description: "You are not authorized to perform this action. Please sign in again."
|
|
111
|
-
},
|
|
112
|
-
ACCESS_DENIED: {
|
|
113
|
-
title: "Access Denied",
|
|
114
|
-
description: "You do not have permission to access this resource. Please contact support if you believe this is an error."
|
|
115
|
-
},
|
|
116
|
-
HAS_NO_PASSWORD: {
|
|
117
|
-
title: "No Password Set",
|
|
118
|
-
description: "Your account does not have a password set (e.g. social login). Please sign in with your provider or reset your password."
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var validCodes = Object.keys(AUTH_ERROR_MAPPING);
|
|
122
|
-
|
|
123
|
-
// src/utils/handle-error.ts
|
|
124
|
-
function isAuthError(err) {
|
|
125
|
-
return typeof err === "object" && err !== null && "message" in err && typeof err.message === "string";
|
|
126
|
-
}
|
|
127
|
-
function extractErrorCode(err) {
|
|
128
|
-
if (err.code && validCodes.includes(err.code)) {
|
|
129
|
-
return err.code;
|
|
130
|
-
}
|
|
131
|
-
if (err.message) {
|
|
132
|
-
const messageUpper = err.message.toUpperCase().trim();
|
|
133
|
-
if (validCodes.includes(messageUpper)) {
|
|
134
|
-
return messageUpper;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return "";
|
|
138
|
-
}
|
|
139
|
-
function handleAuthError(err, setError, t) {
|
|
140
|
-
const errorCode = extractErrorCode(err);
|
|
141
|
-
if (errorCode && AUTH_ERROR_MAPPING[errorCode]) {
|
|
142
|
-
const mapping = AUTH_ERROR_MAPPING[errorCode];
|
|
143
|
-
setError({
|
|
144
|
-
title: mapping.title,
|
|
145
|
-
description: mapping.description
|
|
146
|
-
});
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
setError({
|
|
150
|
-
title: t("errors.fallback"),
|
|
151
|
-
description: err.message || t("errors.fallback")
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function handleGenericError(err, setError, t) {
|
|
155
|
-
const message = err instanceof Error ? err.message : t("errors.fallback");
|
|
156
|
-
setError({
|
|
157
|
-
title: "Error",
|
|
158
|
-
description: message
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
var handleError = (err, setError, t) => {
|
|
162
|
-
if (isAuthError(err)) {
|
|
163
|
-
handleAuthError(err, setError, t);
|
|
164
|
-
} else {
|
|
165
|
-
handleGenericError(err, setError, t);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// src/components/auth/auth-page-layout.tsx
|
|
170
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
171
|
-
var AuthPageLayout = ({
|
|
172
|
-
title,
|
|
173
|
-
description,
|
|
174
|
-
children,
|
|
175
|
-
footer,
|
|
176
|
-
logoImage
|
|
177
|
-
}) => {
|
|
178
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
179
|
-
/* @__PURE__ */ jsx2("div", { className: "flex size-8 mb-6 w-full items-center justify-center rounded-md", children: /* @__PURE__ */ jsx2("img", { src: logoImage || "", alt: "Mesob", width: 42, height: 42 }) }),
|
|
180
|
-
/* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
181
|
-
/* @__PURE__ */ jsx2("h1", { className: "text-2xl font-bold tracking-tight", children: title }),
|
|
182
|
-
description && /* @__PURE__ */ jsx2("p", { className: "mt-2 text-sm text-muted-foreground", children: description })
|
|
183
|
-
] }),
|
|
184
|
-
children,
|
|
185
|
-
/* @__PURE__ */ jsx2("div", { className: "mt-2 w-full", children: footer && /* @__PURE__ */ jsx2("div", { className: "w-full text-center text-sm text-muted-foreground", children: footer }) })
|
|
186
|
-
] });
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// src/components/auth/forgot-password.tsx
|
|
190
|
-
import { zodResolver } from "@hookform/resolvers/zod";
|
|
191
|
-
import { Button } from "@mesob/ui/components/button";
|
|
192
|
-
import {
|
|
193
|
-
Field,
|
|
194
|
-
FieldError,
|
|
195
|
-
FieldGroup,
|
|
196
|
-
FieldLabel
|
|
197
|
-
} from "@mesob/ui/components/field";
|
|
198
|
-
import { Input } from "@mesob/ui/components/input";
|
|
199
|
-
import { Spinner } from "@mesob/ui/components/spinner";
|
|
200
|
-
import { Controller, useForm } from "react-hook-form";
|
|
201
|
-
import { z } from "zod";
|
|
202
|
-
|
|
203
|
-
// src/hooks/use-translator.ts
|
|
204
|
-
function useTranslator(namespace) {
|
|
205
|
-
const { config } = useConfig();
|
|
206
|
-
return createTranslator(config.messages || {}, namespace);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/components/auth/forgot-password.tsx
|
|
210
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
211
|
-
var forgotPasswordSchema = (t) => z.object({
|
|
212
|
-
account: z.string().min(1, t("errors.accountRequired"))
|
|
213
|
-
});
|
|
214
|
-
var ForgotPassword = ({
|
|
215
|
-
onSubmit,
|
|
216
|
-
isLoading = false
|
|
217
|
-
}) => {
|
|
218
|
-
const t = useTranslator("Auth.forgotPassword");
|
|
219
|
-
const form = useForm({
|
|
220
|
-
resolver: zodResolver(forgotPasswordSchema(t)),
|
|
221
|
-
defaultValues: {
|
|
222
|
-
account: ""
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
const handleSubmit = form.handleSubmit(async (values) => {
|
|
226
|
-
await onSubmit(values);
|
|
227
|
-
});
|
|
228
|
-
return /* @__PURE__ */ jsxs2("form", { id: "forgot-password-form", onSubmit: handleSubmit, children: [
|
|
229
|
-
/* @__PURE__ */ jsx3(FieldGroup, { children: /* @__PURE__ */ jsx3(
|
|
230
|
-
Controller,
|
|
231
|
-
{
|
|
232
|
-
name: "account",
|
|
233
|
-
control: form.control,
|
|
234
|
-
render: ({ field, fieldState }) => /* @__PURE__ */ jsxs2(Field, { "data-invalid": fieldState.invalid, children: [
|
|
235
|
-
/* @__PURE__ */ jsx3(FieldLabel, { htmlFor: "forgot-password-account", children: t("form.accountLabel") }),
|
|
236
|
-
/* @__PURE__ */ jsx3(
|
|
237
|
-
Input,
|
|
238
|
-
{
|
|
239
|
-
...field,
|
|
240
|
-
id: "forgot-password-account",
|
|
241
|
-
type: "text",
|
|
242
|
-
placeholder: t("form.accountPlaceholder"),
|
|
243
|
-
"aria-invalid": fieldState.invalid
|
|
244
|
-
}
|
|
245
|
-
),
|
|
246
|
-
fieldState.invalid && /* @__PURE__ */ jsx3(FieldError, { errors: [fieldState.error] })
|
|
247
|
-
] })
|
|
248
|
-
}
|
|
249
|
-
) }),
|
|
250
|
-
/* @__PURE__ */ jsx3("div", { className: "mt-4", children: /* @__PURE__ */ jsxs2(
|
|
251
|
-
Button,
|
|
252
|
-
{
|
|
253
|
-
type: "submit",
|
|
254
|
-
form: "forgot-password-form",
|
|
255
|
-
className: "w-full",
|
|
256
|
-
disabled: isLoading,
|
|
257
|
-
children: [
|
|
258
|
-
isLoading && /* @__PURE__ */ jsx3(Spinner, {}),
|
|
259
|
-
isLoading ? t("form.submitting") : t("form.submit")
|
|
260
|
-
]
|
|
261
|
-
}
|
|
262
|
-
) })
|
|
263
|
-
] });
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// src/components/auth/pages/forgot-password-page.tsx
|
|
267
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
268
|
-
var ForgotPasswordPage = (_props = {}) => {
|
|
269
|
-
const { hooks } = useApi();
|
|
270
|
-
const { config } = useConfig();
|
|
271
|
-
const t = createTranslator(config.messages || {}, "Auth.forgotPassword");
|
|
272
|
-
const [isLoading, setIsLoading] = useState2(false);
|
|
273
|
-
const [error, setError] = useState2(null);
|
|
274
|
-
const forgotPasswordMutation = hooks.useMutation("post", "/password/forgot");
|
|
275
|
-
const signInLink = config.navigation?.links?.signIn || "/auth/sign-in";
|
|
276
|
-
const Link = config.navigation?.linkComponent;
|
|
277
|
-
const onNavigate = config.navigation?.onNavigate || ((path) => {
|
|
278
|
-
if (typeof window !== "undefined") {
|
|
279
|
-
window.location.href = path;
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
const logoImage = config.ui.logoImage;
|
|
283
|
-
useEffect2(() => {
|
|
284
|
-
if (error) {
|
|
285
|
-
toast.error(error.title || "Error", {
|
|
286
|
-
description: error.description
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}, [error]);
|
|
290
|
-
const handleSubmit = async (values) => {
|
|
291
|
-
setIsLoading(true);
|
|
292
|
-
setError(null);
|
|
293
|
-
try {
|
|
294
|
-
const res = await forgotPasswordMutation.mutateAsync({
|
|
295
|
-
body: {
|
|
296
|
-
identifier: values.account
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
if ("verificationId" in res && res.verificationId) {
|
|
300
|
-
onNavigate(`/auth/reset-password?verificationId=${res.verificationId}`);
|
|
301
|
-
} else {
|
|
302
|
-
onNavigate(
|
|
303
|
-
`/auth/reset-password?identifier=${encodeURIComponent(values.account)}`
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
} catch (err) {
|
|
307
|
-
handleError(err, setError, t);
|
|
308
|
-
} finally {
|
|
309
|
-
setIsLoading(false);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
const handleBack = () => {
|
|
313
|
-
onNavigate(signInLink);
|
|
314
|
-
};
|
|
315
|
-
let errorContent = null;
|
|
316
|
-
if (error) {
|
|
317
|
-
if (typeof error === "string") {
|
|
318
|
-
errorContent = { title: "Error", description: error };
|
|
319
|
-
} else {
|
|
320
|
-
errorContent = error;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return /* @__PURE__ */ jsxs3(
|
|
324
|
-
AuthPageLayout,
|
|
325
|
-
{
|
|
326
|
-
title: t("title"),
|
|
327
|
-
description: t("description"),
|
|
328
|
-
logoImage,
|
|
329
|
-
footer: Link ? /* @__PURE__ */ jsx4(Link, { href: signInLink, className: "text-primary hover:underline", children: t("footer.backToSignIn") }) : /* @__PURE__ */ jsx4(
|
|
330
|
-
"a",
|
|
331
|
-
{
|
|
332
|
-
href: signInLink,
|
|
333
|
-
onClick: (e) => {
|
|
334
|
-
e.preventDefault();
|
|
335
|
-
onNavigate(signInLink);
|
|
336
|
-
},
|
|
337
|
-
className: "text-primary hover:underline",
|
|
338
|
-
children: t("footer.backToSignIn")
|
|
339
|
-
}
|
|
340
|
-
),
|
|
341
|
-
children: [
|
|
342
|
-
/* @__PURE__ */ jsx4(
|
|
343
|
-
ForgotPassword,
|
|
344
|
-
{
|
|
345
|
-
onSubmit: handleSubmit,
|
|
346
|
-
isLoading: isLoading || forgotPasswordMutation.isPending,
|
|
347
|
-
onBack: handleBack
|
|
348
|
-
}
|
|
349
|
-
),
|
|
350
|
-
errorContent && /* @__PURE__ */ jsxs3(Alert, { variant: "destructive", className: "mt-4", children: [
|
|
351
|
-
/* @__PURE__ */ jsx4(IconAlertCircle, { className: "h-4 w-4" }),
|
|
352
|
-
/* @__PURE__ */ jsx4(AlertTitle, { children: errorContent.title }),
|
|
353
|
-
/* @__PURE__ */ jsx4(AlertDescription, { children: errorContent.description })
|
|
354
|
-
] })
|
|
355
|
-
]
|
|
356
|
-
}
|
|
357
|
-
);
|
|
358
|
-
};
|
|
359
|
-
export {
|
|
360
|
-
ForgotPasswordPage
|
|
361
|
-
};
|
|
362
|
-
//# sourceMappingURL=forgot-password-page.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/auth/pages/forgot-password-page.tsx","../../../../src/lib/translations.ts","../../../../src/provider.tsx","../../../../src/constants/auth.error.codes.ts","../../../../src/utils/handle-error.ts","../../../../src/components/auth/auth-page-layout.tsx","../../../../src/components/auth/forgot-password.tsx","../../../../src/hooks/use-translator.ts"],"sourcesContent":["'use client';\n\nimport {\n Alert,\n AlertDescription,\n AlertTitle,\n} from '@mesob/ui/components/alert';\nimport { toast } from '@mesob/ui/components/sonner';\nimport { IconAlertCircle } from '@tabler/icons-react';\nimport { useEffect, useState } from 'react';\nimport { createTranslator } from '../../../lib/translations';\nimport { useApi, useConfig } from '../../../provider';\nimport type { AuthErrorContent } from '../../../utils/handle-error';\nimport { handleError } from '../../../utils/handle-error';\n\nimport { AuthPageLayout } from '../auth-page-layout';\nimport { ForgotPassword } from '../forgot-password';\n\ntype ForgotPasswordPageProps = Record<string, never>;\n\nexport const ForgotPasswordPage = (_props: ForgotPasswordPageProps = {}) => {\n const { hooks } = useApi();\n const { config } = useConfig();\n const t = createTranslator(config.messages || {}, 'Auth.forgotPassword');\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<AuthErrorContent | null>(null);\n\n const forgotPasswordMutation = hooks.useMutation('post', '/password/forgot');\n\n const signInLink = config.navigation?.links?.signIn || '/auth/sign-in';\n const Link = config.navigation?.linkComponent;\n const onNavigate =\n config.navigation?.onNavigate ||\n ((path: string) => {\n if (typeof window !== 'undefined') {\n window.location.href = path;\n }\n });\n const logoImage = config.ui.logoImage;\n\n useEffect(() => {\n if (error) {\n toast.error(error.title || 'Error', {\n description: error.description,\n });\n }\n }, [error]);\n\n const handleSubmit = async (values: { account: string }) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const res = await forgotPasswordMutation.mutateAsync({\n body: {\n identifier: values.account,\n },\n });\n\n if ('verificationId' in res && res.verificationId) {\n onNavigate(`/auth/reset-password?verificationId=${res.verificationId}`);\n } else {\n onNavigate(\n `/auth/reset-password?identifier=${encodeURIComponent(values.account)}`,\n );\n }\n } catch (err) {\n handleError(err, setError, t);\n } finally {\n setIsLoading(false);\n }\n };\n\n const handleBack = () => {\n onNavigate(signInLink);\n };\n\n let errorContent: AuthErrorContent | null = null;\n if (error) {\n if (typeof error === 'string') {\n errorContent = { title: 'Error', description: error };\n } else {\n errorContent = error;\n }\n }\n\n return (\n <AuthPageLayout\n title={t('title')}\n description={t('description')}\n logoImage={logoImage}\n footer={\n Link ? (\n <Link href={signInLink} className=\"text-primary hover:underline\">\n {t('footer.backToSignIn')}\n </Link>\n ) : (\n <a\n href={signInLink}\n onClick={(e) => {\n e.preventDefault();\n onNavigate(signInLink);\n }}\n className=\"text-primary hover:underline\"\n >\n {t('footer.backToSignIn')}\n </a>\n )\n }\n >\n <ForgotPassword\n onSubmit={handleSubmit}\n isLoading={isLoading || forgotPasswordMutation.isPending}\n onBack={handleBack}\n />\n {errorContent && (\n <Alert variant=\"destructive\" className=\"mt-4\">\n <IconAlertCircle className=\"h-4 w-4\" />\n <AlertTitle>{errorContent.title}</AlertTitle>\n <AlertDescription>{errorContent.description}</AlertDescription>\n </Alert>\n )}\n </AuthPageLayout>\n );\n};\n","type Messages = Record<string, unknown>;\n\nexport function createTranslator(messages: Messages, namespace?: string) {\n return (key: string, params?: Record<string, string | number>): string => {\n const fullKey = namespace ? `${namespace}.${key}` : key;\n const keys = fullKey.split('.');\n\n let value: unknown = messages;\n for (const k of keys) {\n if (value && typeof value === 'object' && value !== null) {\n value = (value as Record<string, unknown>)[k];\n } else {\n return fullKey;\n }\n }\n\n if (typeof value !== 'string') {\n return fullKey;\n }\n\n // Simple parameter replacement\n if (params) {\n return value.replace(/\\{(\\w+)\\}/g, (_, param) =>\n String(params[param] ?? `{${param}}`),\n );\n }\n\n return value;\n };\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useEffect, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { createCustomFetch } from './utils/custom-fetch';\n\ntype OpenApiHooks = any;\n\ntype SessionState = {\n user: User | null;\n session: Session | null;\n isLoading: boolean;\n isAuthenticated: boolean;\n error: Error | null;\n};\n\ntype SessionContextValue = SessionState & {\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 1000 * 60 * 5,\n gcTime: 1000 * 60 * 10,\n retry: 1,\n refetchOnWindowFocus: false,\n },\n },\n});\n\nexport function useSession() {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi() {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig() {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig;\n\n const api = createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n });\n\n const hooks = createClient(api);\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider config={mergedConfig} hooks={hooks}>\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n children,\n}: AuthStateProviderProps) {\n const [authState, setAuthState] = useState<{\n user: User | null;\n session: Session | null;\n isLoading: boolean;\n error: Error | null;\n }>({\n user: null,\n session: null,\n isLoading: false,\n error: null,\n });\n\n const {\n data: sessionData,\n isLoading: sessionLoading,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: true,\n refetchOnMount: true,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n },\n );\n\n useEffect(() => {\n if (sessionLoading) {\n setAuthState((prev) => ({ ...prev, isLoading: true }));\n return;\n }\n\n if (sessionError) {\n setAuthState({\n user: null,\n session: null,\n isLoading: false,\n error: sessionError as Error,\n });\n return;\n }\n\n if (sessionData) {\n setAuthState({\n user: sessionData.user,\n session: sessionData.session,\n isLoading: false,\n error: null,\n });\n return;\n }\n\n setAuthState({\n user: null,\n session: null,\n isLoading: false,\n error: null,\n });\n }, [sessionData, sessionLoading, sessionError]);\n\n const refresh = async () => {\n await refetch();\n };\n\n const setAuth = (auth: AuthResponse) => {\n setAuthState({\n user: auth.user,\n session: auth.session,\n isLoading: false,\n error: null,\n });\n };\n\n const clearAuth = () => {\n setAuthState({\n user: null,\n session: null,\n isLoading: false,\n error: null,\n });\n };\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n const t = createTranslator(config.messages || {});\n\n return (\n <ConfigContext.Provider value={{ config, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user: authState.user,\n session: authState.session,\n isLoading: authState.isLoading,\n isAuthenticated: !!authState.user && !!authState.session,\n error: authState.error,\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","export const AUTH_ERROR_MAPPING: Record<\n string,\n { title: string; description: string }\n> = {\n USER_NOT_FOUND: {\n title: 'Account Not Found',\n description:\n 'We could not find an account with that identifier. Please check your spelling or sign up.',\n },\n INVALID_PASSWORD: {\n title: 'Invalid Password',\n description: 'The password you entered is incorrect. Please try again.',\n },\n USER_EXISTS: {\n title: 'Account Already Exists',\n description:\n 'An account with this identifier already exists. Please sign in instead.',\n },\n VERIFICATION_EXPIRED: {\n title: 'Verification Expired',\n description:\n 'The verification code or link has expired. Please request a new one.',\n },\n VERIFICATION_MISMATCH: {\n title: 'Invalid Code',\n description:\n 'The verification code you entered is invalid. Please double-check and try again.',\n },\n VERIFICATION_NOT_FOUND: {\n title: 'Verification Not Found',\n description:\n 'We could not find a pending verification request. Please restart the process.',\n },\n TOO_MANY_ATTEMPTS: {\n title: 'Too Many Attempts',\n description:\n 'You have made too many requests recently. Please wait a moment before trying again.',\n },\n REQUIRES_VERIFICATION: {\n title: 'Verification Required',\n description:\n 'You need to verify your account before you can continue. Please check your email or phone.',\n },\n UNAUTHORIZED: {\n title: 'Unauthorized',\n description:\n 'You are not authorized to perform this action. Please sign in again.',\n },\n ACCESS_DENIED: {\n title: 'Access Denied',\n description:\n 'You do not have permission to access this resource. Please contact support if you believe this is an error.',\n },\n HAS_NO_PASSWORD: {\n title: 'No Password Set',\n description:\n 'Your account does not have a password set (e.g. social login). Please sign in with your provider or reset your password.',\n },\n};\n\nexport const validCodes = Object.keys(AUTH_ERROR_MAPPING);\n","import { AUTH_ERROR_MAPPING, validCodes } from '../constants/auth.error.codes';\nimport type { AuthError } from '../types';\n\nexport type AuthErrorContent = {\n title: string;\n description: string;\n};\n\n// Translator function type\ntype TranslatorFunction = (\n key: string,\n params?: Record<string, string | number>,\n) => string;\n\n// Type guard to check if error is an AuthError\nfunction isAuthError(err: unknown): err is AuthError {\n return (\n typeof err === 'object' &&\n err !== null &&\n 'message' in err &&\n typeof (err as { message: unknown }).message === 'string'\n );\n}\n\nfunction extractErrorCode(err: AuthError): string {\n if (err.code && validCodes.includes(err.code)) {\n return err.code;\n }\n if (err.message) {\n const messageUpper = err.message.toUpperCase().trim();\n if (validCodes.includes(messageUpper)) {\n return messageUpper;\n }\n }\n return '';\n}\n\nfunction handleAuthError(\n err: AuthError,\n setError: (error: AuthErrorContent | null) => void,\n t: TranslatorFunction,\n) {\n const errorCode = extractErrorCode(err);\n\n if (errorCode && AUTH_ERROR_MAPPING[errorCode]) {\n const mapping = AUTH_ERROR_MAPPING[errorCode];\n setError({\n title: mapping.title,\n description: mapping.description,\n });\n return;\n }\n\n setError({\n title: t('errors.fallback'),\n description: err.message || t('errors.fallback'),\n });\n}\n\nfunction handleGenericError(\n err: unknown,\n setError: (error: AuthErrorContent | null) => void,\n t: TranslatorFunction,\n) {\n const message = err instanceof Error ? err.message : t('errors.fallback');\n setError({\n title: 'Error',\n description: message,\n });\n}\n\nexport const handleError = (\n err: unknown,\n setError: (error: AuthErrorContent | null) => void,\n t: TranslatorFunction,\n) => {\n if (isAuthError(err)) {\n handleAuthError(err, setError, t);\n } else {\n handleGenericError(err, setError, t);\n }\n};\n","'use client';\n\nimport type { ReactNode } from 'react';\n\ntype AuthPageLayoutProps = {\n title: string;\n description?: string;\n children: ReactNode;\n footer?: ReactNode;\n logoImage?: string;\n};\n\nexport const AuthPageLayout = ({\n title,\n description,\n children,\n footer,\n logoImage,\n}: AuthPageLayoutProps) => {\n return (\n <div className=\"space-y-4\">\n <div className=\"flex size-8 mb-6 w-full items-center justify-center rounded-md\">\n {/** biome-ignore lint/performance/noImgElement: logo image */}\n <img src={logoImage || ''} alt=\"Mesob\" width={42} height={42} />\n </div>\n <div className=\"text-center\">\n <h1 className=\"text-2xl font-bold tracking-tight\">{title}</h1>\n {description && (\n <p className=\"mt-2 text-sm text-muted-foreground\">{description}</p>\n )}\n </div>\n\n {children}\n\n <div className=\"mt-2 w-full\">\n {footer && (\n <div className=\"w-full text-center text-sm text-muted-foreground\">\n {footer}\n </div>\n )}\n </div>\n </div>\n );\n};\n","'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Button } from '@mesob/ui/components/button';\nimport {\n Field,\n FieldError,\n FieldGroup,\n FieldLabel,\n} from '@mesob/ui/components/field';\nimport { Input } from '@mesob/ui/components/input';\nimport { Spinner } from '@mesob/ui/components/spinner';\nimport { Controller, useForm } from 'react-hook-form';\nimport { z } from 'zod';\nimport { useTranslator } from '../../hooks/use-translator';\n\ntype ForgotPasswordFormValues = {\n account: string;\n};\n\ntype ForgotPasswordProps = {\n onSubmit: (values: ForgotPasswordFormValues) => Promise<void> | void;\n isLoading?: boolean;\n onBack?: () => void;\n};\n\nconst forgotPasswordSchema = (t: (key: string) => string) =>\n z.object({\n account: z.string().min(1, t('errors.accountRequired')),\n });\n\nexport const ForgotPassword = ({\n onSubmit,\n isLoading = false,\n}: ForgotPasswordProps) => {\n const t = useTranslator('Auth.forgotPassword');\n\n const form = useForm<ForgotPasswordFormValues>({\n resolver: zodResolver(forgotPasswordSchema(t)),\n defaultValues: {\n account: '',\n },\n });\n\n const handleSubmit = form.handleSubmit(async (values) => {\n await onSubmit(values);\n });\n\n return (\n <form id=\"forgot-password-form\" onSubmit={handleSubmit}>\n <FieldGroup>\n <Controller\n name=\"account\"\n control={form.control}\n render={({ field, fieldState }) => (\n <Field data-invalid={fieldState.invalid}>\n <FieldLabel htmlFor=\"forgot-password-account\">\n {t('form.accountLabel')}\n </FieldLabel>\n <Input\n {...field}\n id=\"forgot-password-account\"\n type=\"text\"\n placeholder={t('form.accountPlaceholder')}\n aria-invalid={fieldState.invalid}\n />\n {fieldState.invalid && <FieldError errors={[fieldState.error]} />}\n </Field>\n )}\n />\n </FieldGroup>\n <div className=\"mt-4\">\n <Button\n type=\"submit\"\n form=\"forgot-password-form\"\n className=\"w-full\"\n disabled={isLoading}\n >\n {isLoading && <Spinner />}\n {isLoading ? t('form.submitting') : t('form.submit')}\n </Button>\n </div>\n </form>\n );\n};\n","import { createTranslator } from '../lib/translations';\nimport { useConfig } from '../provider';\n\nexport function useTranslator(namespace?: string) {\n const { config } = useConfig();\n return createTranslator(config.messages || {}, namespace);\n}\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,aAAAA,YAAW,YAAAC,iBAAgB;;;ACP7B,SAAS,iBAAiB,UAAoB,WAAoB;AACvE,SAAO,CAAC,KAAa,WAAqD;AACxE,UAAM,UAAU,YAAY,GAAG,SAAS,IAAI,GAAG,KAAK;AACpD,UAAM,OAAO,QAAQ,MAAM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xs","useState","useEffect"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
|
|
3
|
-
type ResetPasswordPageProps = {
|
|
4
|
-
verificationId: string;
|
|
5
|
-
redirectUrl?: string;
|
|
6
|
-
};
|
|
7
|
-
declare const ResetPasswordPage: ({ verificationId, redirectUrl, }: ResetPasswordPageProps) => react_jsx_runtime.JSX.Element;
|
|
8
|
-
|
|
9
|
-
export { ResetPasswordPage };
|