@asteby/metacore-auth 2.0.0
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/LICENSE +201 -0
- package/README.md +101 -0
- package/dist/api-client.d.ts +35 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +57 -0
- package/dist/api-client.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +3 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/password-input.d.ts +7 -0
- package/dist/components/password-input.d.ts.map +1 -0
- package/dist/components/password-input.js +10 -0
- package/dist/components/password-input.js.map +1 -0
- package/dist/components/sign-out-dialog.d.ts +16 -0
- package/dist/components/sign-out-dialog.d.ts.map +1 -0
- package/dist/components/sign-out-dialog.js +20 -0
- package/dist/components/sign-out-dialog.js.map +1 -0
- package/dist/guards.d.ts +28 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +33 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/auth-layout.d.ts +14 -0
- package/dist/pages/auth-layout.d.ts.map +1 -0
- package/dist/pages/auth-layout.js +9 -0
- package/dist/pages/auth-layout.js.map +1 -0
- package/dist/pages/forgot-password.d.ts +21 -0
- package/dist/pages/forgot-password.d.ts.map +1 -0
- package/dist/pages/forgot-password.js +33 -0
- package/dist/pages/forgot-password.js.map +1 -0
- package/dist/pages/index.d.ts +11 -0
- package/dist/pages/index.d.ts.map +1 -0
- package/dist/pages/index.js +6 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/otp.d.ts +37 -0
- package/dist/pages/otp.d.ts.map +1 -0
- package/dist/pages/otp.js +50 -0
- package/dist/pages/otp.js.map +1 -0
- package/dist/pages/sign-in.d.ts +54 -0
- package/dist/pages/sign-in.d.ts.map +1 -0
- package/dist/pages/sign-in.js +41 -0
- package/dist/pages/sign-in.js.map +1 -0
- package/dist/pages/sign-up.d.ts +32 -0
- package/dist/pages/sign-up.d.ts.map +1 -0
- package/dist/pages/sign-up.js +54 -0
- package/dist/pages/sign-up.js.map +1 -0
- package/dist/provider.d.ts +35 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +48 -0
- package/dist/provider.js.map +1 -0
- package/dist/store.d.ts +40 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +47 -0
- package/dist/store.js.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Asteby, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @asteby/metacore-auth
|
|
2
|
+
|
|
3
|
+
Metacore auth kit: Zustand store, `createApiClient` factory, TanStack Router
|
|
4
|
+
guard builder, and brand-less sign-in / sign-up / forgot-password / OTP pages.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @asteby/metacore-auth @asteby/metacore-ui zustand @tanstack/react-router
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Peer deps required: `react`, `react-dom`, `@tanstack/react-router`, `zustand`.
|
|
13
|
+
|
|
14
|
+
## Entry points
|
|
15
|
+
|
|
16
|
+
| Import path | Exports |
|
|
17
|
+
| ----------------------------------- | ------------------------------------------------------------ |
|
|
18
|
+
| `@asteby/metacore-auth` | Everything below (re-exported). |
|
|
19
|
+
| `@asteby/metacore-auth/store` | `useAuthStore`, `AuthUser`, `AuthState`, `AUTH_STORAGE_KEYS` |
|
|
20
|
+
| `@asteby/metacore-auth/provider` | `AuthProvider`, `useAuth` |
|
|
21
|
+
| `@asteby/metacore-auth/api-client` | `createApiClient`, `ApiClient` |
|
|
22
|
+
| `@asteby/metacore-auth/guards` | `createAuthGuard` |
|
|
23
|
+
| `@asteby/metacore-auth/pages` | `SignInPage`, `SignUpPage`, `ForgotPasswordPage`, `OtpPage`, `AuthLayout` |
|
|
24
|
+
| `@asteby/metacore-auth/components` | `PasswordInput`, `SignOutDialog` |
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
### 1. Create the API client (once, at boot)
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createApiClient, useAuthStore } from '@asteby/metacore-auth'
|
|
32
|
+
import i18n from './i18n'
|
|
33
|
+
|
|
34
|
+
export const api = createApiClient({
|
|
35
|
+
baseURL: import.meta.env.VITE_API_URL ?? '/api',
|
|
36
|
+
getToken: () => useAuthStore.getState().auth.accessToken,
|
|
37
|
+
getLanguage: () => i18n.language,
|
|
38
|
+
getBranchId: () => {
|
|
39
|
+
try {
|
|
40
|
+
const branch = JSON.parse(localStorage.getItem('current_branch') || '{}')
|
|
41
|
+
return branch?.id
|
|
42
|
+
} catch {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
onUnauthorized: () => {
|
|
47
|
+
useAuthStore.getState().auth.reset()
|
|
48
|
+
window.location.href = '/sign-in'
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Guard authenticated routes
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// src/routes/_authenticated/route.tsx
|
|
57
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
58
|
+
import { createAuthGuard } from '@asteby/metacore-auth/guards'
|
|
59
|
+
import { AuthenticatedLayout } from '@/components/layout/authenticated-layout'
|
|
60
|
+
|
|
61
|
+
export const Route = createFileRoute('/_authenticated')({
|
|
62
|
+
beforeLoad: createAuthGuard(),
|
|
63
|
+
component: AuthenticatedLayout,
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 3. Render branded sign-in
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { SignInPage } from '@asteby/metacore-auth/pages'
|
|
71
|
+
import { useAuthStore } from '@asteby/metacore-auth/store'
|
|
72
|
+
import { useNavigate, Link } from '@tanstack/react-router'
|
|
73
|
+
import { Logo } from '@/assets/logo'
|
|
74
|
+
import { api } from '@/lib/api'
|
|
75
|
+
|
|
76
|
+
export function SignInRoute() {
|
|
77
|
+
const navigate = useNavigate()
|
|
78
|
+
const { auth } = useAuthStore()
|
|
79
|
+
return (
|
|
80
|
+
<SignInPage
|
|
81
|
+
brandName='MyApp'
|
|
82
|
+
logo={<Logo className='size-7' />}
|
|
83
|
+
showcase={<MyErpShowcase />}
|
|
84
|
+
forgotPasswordSlot={<Link to='/forgot-password'>¿Olvidaste tu contraseña?</Link>}
|
|
85
|
+
onSubmit={async ({ email, password, redirectTo }) => {
|
|
86
|
+
const { data } = await api.post('/auth/login', { email, password })
|
|
87
|
+
auth.setUser(data.data.user)
|
|
88
|
+
auth.setAccessToken(data.data.token)
|
|
89
|
+
navigate({ to: redirectTo || '/' })
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Design notes
|
|
97
|
+
|
|
98
|
+
- **Zustand store is canonical** — matches the Ops frontend shape (user + token + reset). Persists to `localStorage` keys `auth_token` / `auth_user`.
|
|
99
|
+
- **Factory, not singleton** — `createApiClient` avoids baking env vars into the library. The host app wires token / language / branch getters.
|
|
100
|
+
- **Pages are brand-less** — accept `brandName`, `logo`, `showcase`, `headerSlot`, `footerSlot` so each app supplies its own identity.
|
|
101
|
+
- **`onSubmit` delegated** — pages don't assume endpoints, toasts, or navigation. The caller owns the network layer.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
export interface CreateApiClientOptions {
|
|
3
|
+
/** Base URL for the axios instance. */
|
|
4
|
+
baseURL: string;
|
|
5
|
+
/**
|
|
6
|
+
* Synchronous token getter. Returning an empty string or `null` skips the
|
|
7
|
+
* Authorization header.
|
|
8
|
+
*/
|
|
9
|
+
getToken?: () => string | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Synchronous getter for the `Accept-Language` header value (e.g. the
|
|
12
|
+
* current i18n language). Defaults to `'es'` if omitted.
|
|
13
|
+
*/
|
|
14
|
+
getLanguage?: () => string | null | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Synchronous getter for the current branch id — sent as `X-Branch-ID`.
|
|
17
|
+
* Return `null` / `undefined` to skip the header.
|
|
18
|
+
*/
|
|
19
|
+
getBranchId?: () => string | number | null | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Called when the server responds with 401. Use this to clear auth state and
|
|
22
|
+
* redirect to the sign-in page. The returned promise (if any) is awaited
|
|
23
|
+
* before the original error is rejected.
|
|
24
|
+
*/
|
|
25
|
+
onUnauthorized?: () => void | Promise<void>;
|
|
26
|
+
/** Extra axios defaults (headers, timeout, etc). Merged into `axios.create`. */
|
|
27
|
+
axiosConfig?: Omit<AxiosRequestConfig, 'baseURL'>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Factory for an axios instance wired with Metacore's auth + i18n + multi-branch
|
|
31
|
+
* conventions. Call once at app bootstrap, then share the returned instance.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createApiClient(options: CreateApiClientOptions): AxiosInstance;
|
|
34
|
+
export type ApiClient = ReturnType<typeof createApiClient>;
|
|
35
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAE9D,MAAM,WAAW,sBAAsB;IACrC,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC1C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,gFAAgF;IAChF,WAAW,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAA;CAClD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa,CAuE9E;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Factory for an axios instance wired with Metacore's auth + i18n + multi-branch
|
|
4
|
+
* conventions. Call once at app bootstrap, then share the returned instance.
|
|
5
|
+
*/
|
|
6
|
+
export function createApiClient(options) {
|
|
7
|
+
const { baseURL, getToken, getLanguage, getBranchId, onUnauthorized, axiosConfig, } = options;
|
|
8
|
+
const instance = axios.create({
|
|
9
|
+
baseURL,
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
...axiosConfig?.headers,
|
|
13
|
+
},
|
|
14
|
+
...axiosConfig,
|
|
15
|
+
});
|
|
16
|
+
instance.interceptors.request.use((config) => {
|
|
17
|
+
const token = getToken?.();
|
|
18
|
+
if (token) {
|
|
19
|
+
config.headers.set?.('Authorization', `Bearer ${token}`);
|
|
20
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
21
|
+
}
|
|
22
|
+
const language = getLanguage?.() || 'es';
|
|
23
|
+
config.headers['Accept-Language'] = language;
|
|
24
|
+
const branchId = getBranchId?.();
|
|
25
|
+
if (branchId !== undefined && branchId !== null && branchId !== '') {
|
|
26
|
+
;
|
|
27
|
+
config.headers['X-Branch-ID'] = String(branchId);
|
|
28
|
+
}
|
|
29
|
+
// Let the browser set Content-Type (incl. boundary) for FormData uploads.
|
|
30
|
+
if (config.data instanceof FormData) {
|
|
31
|
+
delete config.headers['Content-Type'];
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
});
|
|
35
|
+
instance.interceptors.response.use((response) => response, async (error) => {
|
|
36
|
+
const status = error?.response?.status;
|
|
37
|
+
const data = error?.response?.data;
|
|
38
|
+
const url = (error?.config?.method?.toUpperCase?.() ?? 'REQ') +
|
|
39
|
+
' ' +
|
|
40
|
+
(error?.config?.url ?? '');
|
|
41
|
+
const serverMessage = data?.message || data?.error || data?.title || error?.message;
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.error(`[API Error] ${url} → ${status}: ${serverMessage}`, data);
|
|
44
|
+
if (status === 401 && onUnauthorized) {
|
|
45
|
+
try {
|
|
46
|
+
await onUnauthorized();
|
|
47
|
+
}
|
|
48
|
+
catch (handlerErr) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.error('[API Error] onUnauthorized handler threw', handlerErr);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Promise.reject(error);
|
|
54
|
+
});
|
|
55
|
+
return instance;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA+BzB;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAA+B;IAC7D,MAAM,EACJ,OAAO,EACP,QAAQ,EACR,WAAW,EACX,WAAW,EACX,cAAc,EACd,WAAW,GACZ,GAAG,OAAO,CAAA;IAEX,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;QACP,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,GAAI,WAAW,EAAE,OAA8C;SAChE;QACD,GAAG,WAAW;KACf,CAAC,CAAA;IAEF,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,QAAQ,EAAE,EAAE,CAAA;QAC1B,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAEvD;YAAC,MAAM,CAAC,OAAmC,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAA;QAChF,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,EAAE,EAAE,IAAI,IAAI,CACvC;QAAC,MAAM,CAAC,OAAmC,CAAC,iBAAiB,CAAC,GAAG,QAAQ,CAAA;QAE1E,MAAM,QAAQ,GAAG,WAAW,EAAE,EAAE,CAAA;QAChC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;YACnE,CAAC;YAAC,MAAM,CAAC,OAAmC,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QAChF,CAAC;QAED,0EAA0E;QAC1E,IAAI,MAAM,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;YACpC,OAAQ,MAAM,CAAC,OAAmC,CAAC,cAAc,CAAC,CAAA;QACpE,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EACtB,KAAK,EAAE,KAAK,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAA;QACtC,MAAM,IAAI,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAA;QAClC,MAAM,GAAG,GACP,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,KAAK,CAAC;YACjD,GAAG;YACH,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;QAC5B,MAAM,aAAa,GACjB,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,KAAK,EAAE,OAAO,CAAA;QAC/D,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,eAAe,GAAG,MAAM,MAAM,KAAK,aAAa,EAAE,EAAE,IAAI,CAAC,CAAA;QAEvE,IAAI,MAAM,KAAK,GAAG,IAAI,cAAc,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,cAAc,EAAE,CAAA;YACxB,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,UAAU,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC,CACF,CAAA;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type PasswordInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> & {
|
|
3
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
4
|
+
};
|
|
5
|
+
export declare function PasswordInput({ className, disabled, ref, ...props }: PasswordInputProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=password-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-input.d.ts","sourceRoot":"","sources":["../../src/components/password-input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,KAAK,kBAAkB,GAAG,IAAI,CAC5B,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAC3C,MAAM,CACP,GAAG;IACF,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;CAClC,CAAA;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,GAAG,EACH,GAAG,KAAK,EACT,EAAE,kBAAkB,2CAwBpB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Eye, EyeOff } from 'lucide-react';
|
|
4
|
+
import { Button } from '@asteby/metacore-ui/primitives';
|
|
5
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
6
|
+
export function PasswordInput({ className, disabled, ref, ...props }) {
|
|
7
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
8
|
+
return (_jsxs("div", { className: cn('relative rounded-md', className), children: [_jsx("input", { type: showPassword ? 'text' : 'password', className: 'border-input placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50', ref: ref, disabled: disabled, ...props }), _jsx(Button, { type: 'button', size: 'icon', variant: 'ghost', disabled: disabled, className: 'text-muted-foreground absolute end-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md', onClick: () => setShowPassword((prev) => !prev), children: showPassword ? _jsx(Eye, { size: 18 }) : _jsx(EyeOff, { size: 18 }) })] }));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=password-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-input.js","sourceRoot":"","sources":["../../src/components/password-input.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAA;AAS5C,MAAM,UAAU,aAAa,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,GAAG,EACH,GAAG,KAAK,EACW;IACnB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE7D,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,aAClD,gBACE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EACxC,SAAS,EAAC,yUAAyU,EACnV,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,KACd,KAAK,GACT,EACF,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,MAAM,EACX,OAAO,EAAC,OAAO,EACf,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAC,kFAAkF,EAC5F,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAE9C,YAAY,CAAC,CAAC,CAAC,KAAC,GAAG,IAAC,IAAI,EAAE,EAAE,GAAI,CAAC,CAAC,CAAC,KAAC,MAAM,IAAC,IAAI,EAAE,EAAE,GAAI,GACjD,IACL,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface SignOutDialogProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
onOpenChange: (open: boolean) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Path to redirect to after sign-out. Default `/sign-in`.
|
|
6
|
+
*/
|
|
7
|
+
signInPath?: string;
|
|
8
|
+
/** Dialog title. */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** Dialog description. */
|
|
11
|
+
desc?: string;
|
|
12
|
+
/** Confirm button text. */
|
|
13
|
+
confirmText?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function SignOutDialog({ open, onOpenChange, signInPath, title, desc, confirmText, }: SignOutDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=sign-out-dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-out-dialog.d.ts","sourceRoot":"","sources":["../../src/components/sign-out-dialog.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,YAAY,EACZ,UAAuB,EACvB,KAAuB,EACvB,IAAmH,EACnH,WAA6B,GAC9B,EAAE,kBAAkB,2CA2BpB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useNavigate, useLocation } from '@tanstack/react-router';
|
|
3
|
+
import { ConfirmDialog } from '@asteby/metacore-ui/dialogs';
|
|
4
|
+
import { useAuthStore } from '../store';
|
|
5
|
+
export function SignOutDialog({ open, onOpenChange, signInPath = '/sign-in', title = 'Cerrar sesión', desc = '¿Estás seguro de que deseas cerrar sesión? Tendrás que iniciar sesión nuevamente para acceder a tu cuenta.', confirmText = 'Cerrar sesión', }) {
|
|
6
|
+
const navigate = useNavigate();
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
const { auth } = useAuthStore();
|
|
9
|
+
const handleSignOut = () => {
|
|
10
|
+
auth.reset();
|
|
11
|
+
const currentPath = location.href;
|
|
12
|
+
navigate({
|
|
13
|
+
to: signInPath,
|
|
14
|
+
search: { redirect: currentPath },
|
|
15
|
+
replace: true,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
return (_jsx(ConfirmDialog, { open: open, onOpenChange: onOpenChange, title: title, desc: desc, confirmText: confirmText, destructive: true, handleConfirm: handleSignOut, className: 'sm:max-w-sm' }));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=sign-out-dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-out-dialog.js","sourceRoot":"","sources":["../../src/components/sign-out-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAiBvC,MAAM,UAAU,aAAa,CAAC,EAC5B,IAAI,EACJ,YAAY,EACZ,UAAU,GAAG,UAAU,EACvB,KAAK,GAAG,eAAe,EACvB,IAAI,GAAG,4GAA4G,EACnH,WAAW,GAAG,eAAe,GACV;IACnB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,CAAA;IAE/B,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAA;QACjC,QAAQ,CAAC;YACP,EAAE,EAAE,UAAmB;YACvB,MAAM,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAW;YAC1C,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,OAAO,CACL,KAAC,aAAa,IACZ,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,WAAW,QACX,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAC,aAAa,GACvB,CACH,CAAA;AACH,CAAC"}
|
package/dist/guards.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CreateAuthGuardOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Route to redirect to when the user is not authenticated.
|
|
4
|
+
* Default: `/sign-in`.
|
|
5
|
+
*/
|
|
6
|
+
signInPath?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Optional hook that runs after the auth check passes. Useful for prefetching
|
|
9
|
+
* metadata or warming caches once the user is known. Exceptions are swallowed
|
|
10
|
+
* so they don't block navigation.
|
|
11
|
+
*/
|
|
12
|
+
afterAuth?: () => void | Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Override how the current path is derived for the `redirect` search param.
|
|
15
|
+
* Defaults to `window.location.pathname`.
|
|
16
|
+
*/
|
|
17
|
+
getCurrentPath?: () => string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a `beforeLoad` function for TanStack Router. Usage:
|
|
21
|
+
*
|
|
22
|
+
* export const Route = createFileRoute('/_authenticated')({
|
|
23
|
+
* beforeLoad: createAuthGuard({ afterAuth: () => useMetadataCache.getState().prefetchAll() }),
|
|
24
|
+
* component: AuthenticatedLayout,
|
|
25
|
+
* })
|
|
26
|
+
*/
|
|
27
|
+
export declare function createAuthGuard(options?: CreateAuthGuardOptions): () => void;
|
|
28
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,MAAM,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,cA2BnE"}
|
package/dist/guards.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { redirect } from '@tanstack/react-router';
|
|
2
|
+
import { useAuthStore } from './store';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `beforeLoad` function for TanStack Router. Usage:
|
|
5
|
+
*
|
|
6
|
+
* export const Route = createFileRoute('/_authenticated')({
|
|
7
|
+
* beforeLoad: createAuthGuard({ afterAuth: () => useMetadataCache.getState().prefetchAll() }),
|
|
8
|
+
* component: AuthenticatedLayout,
|
|
9
|
+
* })
|
|
10
|
+
*/
|
|
11
|
+
export function createAuthGuard(options = {}) {
|
|
12
|
+
const { signInPath = '/sign-in', afterAuth, getCurrentPath = () => typeof window !== 'undefined' ? window.location.pathname : '/', } = options;
|
|
13
|
+
return function beforeLoad() {
|
|
14
|
+
const { auth } = useAuthStore.getState();
|
|
15
|
+
if (!auth.accessToken || !auth.user) {
|
|
16
|
+
throw redirect({
|
|
17
|
+
to: signInPath,
|
|
18
|
+
search: {
|
|
19
|
+
redirect: getCurrentPath(),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (afterAuth) {
|
|
24
|
+
try {
|
|
25
|
+
void afterAuth();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
/* swallow — never block navigation */
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAqBtC;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkC,EAAE;IAClE,MAAM,EACJ,UAAU,GAAG,UAAU,EACvB,SAAS,EACT,cAAc,GAAG,GAAG,EAAE,CACpB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,GACjE,GAAG,OAAO,CAAA;IAEX,OAAO,SAAS,UAAU;QACxB,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAA;QACxC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC;gBACb,EAAE,EAAE,UAAU;gBACd,MAAM,EAAE;oBACN,QAAQ,EAAE,cAAc,EAAE;iBAC3B;aACF,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC;gBACH,KAAK,SAAS,EAAE,CAAA;YAClB,CAAC;YAAC,MAAM,CAAC;gBACP,sCAAsC;YACxC,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { useAuthStore, AUTH_STORAGE_KEYS } from './store';
|
|
2
|
+
export type { AuthUser, AuthState } from './store';
|
|
3
|
+
export { AuthProvider, useAuth } from './provider';
|
|
4
|
+
export type { AuthProviderProps } from './provider';
|
|
5
|
+
export { createApiClient } from './api-client';
|
|
6
|
+
export type { CreateApiClientOptions, ApiClient } from './api-client';
|
|
7
|
+
export { createAuthGuard } from './guards';
|
|
8
|
+
export type { CreateAuthGuardOptions } from './guards';
|
|
9
|
+
export * from './pages';
|
|
10
|
+
export * from './components';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AACzD,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAGtD,cAAc,SAAS,CAAA;AAGvB,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Store
|
|
2
|
+
export { useAuthStore, AUTH_STORAGE_KEYS } from './store';
|
|
3
|
+
// Provider
|
|
4
|
+
export { AuthProvider, useAuth } from './provider';
|
|
5
|
+
// API client factory
|
|
6
|
+
export { createApiClient } from './api-client';
|
|
7
|
+
// Route guards
|
|
8
|
+
export { createAuthGuard } from './guards';
|
|
9
|
+
// Pages
|
|
10
|
+
export * from './pages';
|
|
11
|
+
// Components
|
|
12
|
+
export * from './components';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGzD,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGlD,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAG1C,QAAQ;AACR,cAAc,SAAS,CAAA;AAEvB,aAAa;AACb,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface AuthLayoutProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
/** Slot for the brand logo (rendered at the top, centered). */
|
|
5
|
+
logo?: ReactNode;
|
|
6
|
+
/** Brand name displayed next to the logo. */
|
|
7
|
+
brandName?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Minimal centered auth layout — drop children in and optionally pass a logo
|
|
11
|
+
* slot + brand name. No hardcoded branding.
|
|
12
|
+
*/
|
|
13
|
+
export declare function AuthLayout({ children, logo, brandName }: AuthLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=auth-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-layout.d.ts","sourceRoot":"","sources":["../../src/pages/auth-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,SAAS,CAAA;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,eAAe,2CAcxE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal centered auth layout — drop children in and optionally pass a logo
|
|
4
|
+
* slot + brand name. No hardcoded branding.
|
|
5
|
+
*/
|
|
6
|
+
export function AuthLayout({ children, logo, brandName }) {
|
|
7
|
+
return (_jsx("div", { className: 'container grid h-svh max-w-none items-center justify-center', children: _jsxs("div", { className: 'mx-auto flex w-full flex-col justify-center space-y-2 py-8 sm:w-[480px] sm:p-8', children: [(logo || brandName) && (_jsxs("div", { className: 'mb-4 flex items-center justify-center', children: [logo && _jsx("span", { className: 'me-2', children: logo }), brandName && _jsx("h1", { className: 'text-xl font-medium', children: brandName })] })), children] }) }));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=auth-layout.js.map
|