@fonderie/vue-auth 0.1.0 → 0.3.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/README.md +22 -4
- package/dist/index.cjs +64 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -11
- package/dist/index.d.ts +16 -11
- package/dist/index.js +38 -18
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Vue 3 composables for Fonderie auth — `useLogin`, `useRegister`,
|
|
4
4
|
`useSession`, `useLogout`, `useForgotPassword`, `useResetPassword`, and
|
|
5
5
|
`useVerifyEmail`. Thin bindings over
|
|
6
|
-
[`@fonderie/client`](https://github.com/
|
|
6
|
+
[`@fonderie/client`](https://github.com/fonderiejs/sdk/tree/main/packages/client):
|
|
7
7
|
reactive `ref`s for loading/error/data state and the request itself, nothing
|
|
8
8
|
else. Bring your own UI.
|
|
9
9
|
|
|
@@ -13,6 +13,24 @@ else. Bring your own UI.
|
|
|
13
13
|
npm install @fonderie/vue-auth
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## One client at the root (recommended)
|
|
17
|
+
|
|
18
|
+
Install the plugin from [`@fonderie/vue`](../vue) once (or call
|
|
19
|
+
`provideFonderie(client)` in a root `setup()`) and every composable resolves
|
|
20
|
+
the client by injection — no client argument at call sites:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { FonderiePlugin } from "@fonderie/vue";
|
|
24
|
+
|
|
25
|
+
createApp(App).use(FonderiePlugin, client).mount("#app");
|
|
26
|
+
|
|
27
|
+
// in any component setup():
|
|
28
|
+
const { ...state } = useLogin();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Passing a client explicitly (as below) still works everywhere and takes
|
|
32
|
+
precedence over injection — handy in tests and multi-client apps.
|
|
33
|
+
|
|
16
34
|
## Use
|
|
17
35
|
|
|
18
36
|
```vue
|
|
@@ -39,14 +57,14 @@ or a prop). The access token is persisted to `localStorage` and restored
|
|
|
39
57
|
automatically by `useSession` on setup; don't re-implement that in app code.
|
|
40
58
|
|
|
41
59
|
Want pre-built screens instead of wiring your own form?
|
|
42
|
-
See [`@fonderie/vue-auth-screens`](https://github.com/
|
|
60
|
+
See [`@fonderie/vue-auth-screens`](https://github.com/fonderiejs/sdk/tree/main/packages/vue-auth-screens).
|
|
43
61
|
|
|
44
62
|
## Why this exists
|
|
45
63
|
|
|
46
64
|
You've shipped this plumbing before — auth, teams, billing, messaging —
|
|
47
65
|
and the next project will ask for it again. Fonderie packages it once:
|
|
48
66
|
plain TypeScript modules for
|
|
49
|
-
[`@fonderie/core`](https://github.com/
|
|
67
|
+
[`@fonderie/core`](https://github.com/fonderiejs/sdk/tree/main/packages/core),
|
|
50
68
|
PostgreSQL-backed, self-hosted, MIT. No external control plane, no
|
|
51
69
|
per-seat anything. Register the modules you need; skip the ones you don't.
|
|
52
70
|
|
|
@@ -55,7 +73,7 @@ around `@fonderie/client`, nothing more. No business logic lives here; it
|
|
|
55
73
|
lives in `@fonderie/auth` on the server.
|
|
56
74
|
|
|
57
75
|
Browse the whole set at
|
|
58
|
-
[
|
|
76
|
+
[fonderiejs/sdk](https://github.com/fonderiejs/sdk) · follow
|
|
59
77
|
[@fonderiejs](https://x.com/fonderiejs)
|
|
60
78
|
|
|
61
79
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -34,16 +34,18 @@ var import_client7 = require("@fonderie/client");
|
|
|
34
34
|
|
|
35
35
|
// src/composables/useForgotPassword.ts
|
|
36
36
|
var import_client = require("@fonderie/client");
|
|
37
|
-
var import_vue = require("vue");
|
|
37
|
+
var import_vue = require("@fonderie/vue");
|
|
38
|
+
var import_vue2 = require("vue");
|
|
38
39
|
function useForgotPassword(client) {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const auth = (0, import_vue.useFonderieSubClient)(client, (c) => c.auth, "useForgotPassword");
|
|
41
|
+
const isLoading = (0, import_vue2.ref)(false);
|
|
42
|
+
const error = (0, import_vue2.ref)(null);
|
|
43
|
+
const sent = (0, import_vue2.ref)(false);
|
|
42
44
|
async function forgotPassword(email) {
|
|
43
45
|
isLoading.value = true;
|
|
44
46
|
error.value = null;
|
|
45
47
|
try {
|
|
46
|
-
await
|
|
48
|
+
await auth.forgotPassword(email);
|
|
47
49
|
sent.value = true;
|
|
48
50
|
} catch (err) {
|
|
49
51
|
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
@@ -58,7 +60,8 @@ function useForgotPassword(client) {
|
|
|
58
60
|
|
|
59
61
|
// src/composables/useLogin.ts
|
|
60
62
|
var import_client2 = require("@fonderie/client");
|
|
61
|
-
var
|
|
63
|
+
var import_vue3 = require("@fonderie/vue");
|
|
64
|
+
var import_vue4 = require("vue");
|
|
62
65
|
|
|
63
66
|
// src/storage.ts
|
|
64
67
|
var TOKEN_KEY = "fonderie_access_token";
|
|
@@ -74,15 +77,22 @@ function readToken() {
|
|
|
74
77
|
|
|
75
78
|
// src/composables/useLogin.ts
|
|
76
79
|
function useLogin(client) {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
+
const auth = (0, import_vue3.useFonderieSubClient)(client, (c) => c.auth, "useLogin");
|
|
81
|
+
const isLoading = (0, import_vue4.ref)(false);
|
|
82
|
+
const error = (0, import_vue4.ref)(null);
|
|
83
|
+
const data = (0, import_vue4.ref)(null);
|
|
84
|
+
const mfaPending = (0, import_vue4.ref)(null);
|
|
80
85
|
async function login(input) {
|
|
81
86
|
isLoading.value = true;
|
|
82
87
|
error.value = null;
|
|
88
|
+
mfaPending.value = null;
|
|
83
89
|
try {
|
|
84
|
-
const { result } = await
|
|
85
|
-
|
|
90
|
+
const { result } = await auth.login(input);
|
|
91
|
+
if ((0, import_client2.isMfaRequired)(result)) {
|
|
92
|
+
mfaPending.value = result;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
auth.setAccessToken(result.tokens.access);
|
|
86
96
|
persistToken(result.tokens.access);
|
|
87
97
|
data.value = result;
|
|
88
98
|
return result;
|
|
@@ -94,25 +104,27 @@ function useLogin(client) {
|
|
|
94
104
|
isLoading.value = false;
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
|
-
return { login, isLoading, error, data };
|
|
107
|
+
return { login, isLoading, error, data, mfaPending };
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
// src/composables/useLogout.ts
|
|
101
111
|
var import_client3 = require("@fonderie/client");
|
|
102
|
-
var
|
|
112
|
+
var import_vue5 = require("@fonderie/vue");
|
|
113
|
+
var import_vue6 = require("vue");
|
|
103
114
|
function useLogout(client) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
115
|
+
const auth = (0, import_vue5.useFonderieSubClient)(client, (c) => c.auth, "useLogout");
|
|
116
|
+
const isLoading = (0, import_vue6.ref)(false);
|
|
117
|
+
const error = (0, import_vue6.ref)(null);
|
|
118
|
+
async function logout(refreshToken) {
|
|
107
119
|
isLoading.value = true;
|
|
108
120
|
error.value = null;
|
|
109
121
|
try {
|
|
110
|
-
await
|
|
122
|
+
await auth.logout(refreshToken);
|
|
111
123
|
} catch (err) {
|
|
112
124
|
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
113
125
|
error.value = apiError;
|
|
114
126
|
} finally {
|
|
115
|
-
|
|
127
|
+
auth.setAccessToken(void 0);
|
|
116
128
|
clearToken();
|
|
117
129
|
isLoading.value = false;
|
|
118
130
|
}
|
|
@@ -122,17 +134,19 @@ function useLogout(client) {
|
|
|
122
134
|
|
|
123
135
|
// src/composables/useRegister.ts
|
|
124
136
|
var import_client4 = require("@fonderie/client");
|
|
125
|
-
var
|
|
137
|
+
var import_vue7 = require("@fonderie/vue");
|
|
138
|
+
var import_vue8 = require("vue");
|
|
126
139
|
function useRegister(client) {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const
|
|
140
|
+
const auth = (0, import_vue7.useFonderieSubClient)(client, (c) => c.auth, "useRegister");
|
|
141
|
+
const isLoading = (0, import_vue8.ref)(false);
|
|
142
|
+
const error = (0, import_vue8.ref)(null);
|
|
143
|
+
const data = (0, import_vue8.ref)(null);
|
|
130
144
|
async function register(input) {
|
|
131
145
|
isLoading.value = true;
|
|
132
146
|
error.value = null;
|
|
133
147
|
try {
|
|
134
|
-
const { result } = await
|
|
135
|
-
|
|
148
|
+
const { result } = await auth.register(input);
|
|
149
|
+
auth.setAccessToken(result.tokens.access);
|
|
136
150
|
persistToken(result.tokens.access);
|
|
137
151
|
data.value = result;
|
|
138
152
|
return result;
|
|
@@ -149,16 +163,18 @@ function useRegister(client) {
|
|
|
149
163
|
|
|
150
164
|
// src/composables/useResetPassword.ts
|
|
151
165
|
var import_client5 = require("@fonderie/client");
|
|
152
|
-
var
|
|
166
|
+
var import_vue9 = require("@fonderie/vue");
|
|
167
|
+
var import_vue10 = require("vue");
|
|
153
168
|
function useResetPassword(client) {
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const
|
|
169
|
+
const auth = (0, import_vue9.useFonderieSubClient)(client, (c) => c.auth, "useResetPassword");
|
|
170
|
+
const isLoading = (0, import_vue10.ref)(false);
|
|
171
|
+
const error = (0, import_vue10.ref)(null);
|
|
172
|
+
const done = (0, import_vue10.ref)(false);
|
|
157
173
|
async function resetPassword(input) {
|
|
158
174
|
isLoading.value = true;
|
|
159
175
|
error.value = null;
|
|
160
176
|
try {
|
|
161
|
-
await
|
|
177
|
+
await auth.resetPassword(input);
|
|
162
178
|
done.value = true;
|
|
163
179
|
} catch (err) {
|
|
164
180
|
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
@@ -172,54 +188,58 @@ function useResetPassword(client) {
|
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
// src/composables/useSession.ts
|
|
175
|
-
var
|
|
191
|
+
var import_vue11 = require("@fonderie/vue");
|
|
192
|
+
var import_vue12 = require("vue");
|
|
176
193
|
function useSession(client) {
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
194
|
+
const auth = (0, import_vue11.useFonderieSubClient)(client, (c) => c.auth, "useSession");
|
|
195
|
+
const user = (0, import_vue12.ref)(null);
|
|
196
|
+
const isLoading = (0, import_vue12.ref)(true);
|
|
197
|
+
const isAuthenticated = (0, import_vue12.ref)(false);
|
|
180
198
|
async function refresh() {
|
|
181
199
|
isLoading.value = true;
|
|
182
200
|
try {
|
|
183
|
-
const { result } = await
|
|
201
|
+
const { result } = await auth.getUser();
|
|
184
202
|
user.value = result.user;
|
|
185
203
|
isAuthenticated.value = true;
|
|
186
204
|
} catch {
|
|
187
205
|
user.value = null;
|
|
188
206
|
isAuthenticated.value = false;
|
|
189
|
-
|
|
207
|
+
auth.setAccessToken(void 0);
|
|
190
208
|
clearToken();
|
|
191
209
|
} finally {
|
|
192
210
|
isLoading.value = false;
|
|
193
211
|
}
|
|
194
212
|
}
|
|
195
|
-
async function logout() {
|
|
213
|
+
async function logout(refreshToken) {
|
|
196
214
|
try {
|
|
197
|
-
await
|
|
215
|
+
await auth.logout(refreshToken);
|
|
198
216
|
} catch {
|
|
199
217
|
}
|
|
200
|
-
|
|
218
|
+
auth.setAccessToken(void 0);
|
|
201
219
|
clearToken();
|
|
202
220
|
user.value = null;
|
|
203
221
|
isAuthenticated.value = false;
|
|
204
222
|
}
|
|
205
223
|
const token = readToken();
|
|
206
|
-
if (token)
|
|
224
|
+
if (token) auth.setAccessToken(token);
|
|
207
225
|
void refresh();
|
|
208
226
|
return { user, isLoading, isAuthenticated, refresh, logout };
|
|
209
227
|
}
|
|
210
228
|
|
|
211
229
|
// src/composables/useVerifyEmail.ts
|
|
212
230
|
var import_client6 = require("@fonderie/client");
|
|
213
|
-
var
|
|
231
|
+
var import_vue13 = require("@fonderie/vue");
|
|
232
|
+
var import_vue14 = require("vue");
|
|
214
233
|
function useVerifyEmail(client) {
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
234
|
+
const auth = (0, import_vue13.useFonderieSubClient)(client, (c) => c.auth, "useVerifyEmail");
|
|
235
|
+
const isLoading = (0, import_vue14.ref)(false);
|
|
236
|
+
const error = (0, import_vue14.ref)(null);
|
|
237
|
+
const data = (0, import_vue14.ref)(null);
|
|
218
238
|
async function verifyEmail(pin) {
|
|
219
239
|
isLoading.value = true;
|
|
220
240
|
error.value = null;
|
|
221
241
|
try {
|
|
222
|
-
const { result } = await
|
|
242
|
+
const { result } = await auth.verifyEmail(pin);
|
|
223
243
|
data.value = result;
|
|
224
244
|
return result;
|
|
225
245
|
} catch (err) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/composables/useForgotPassword.ts","../src/composables/useLogin.ts","../src/storage.ts","../src/composables/useLogout.ts","../src/composables/useRegister.ts","../src/composables/useResetPassword.ts","../src/composables/useSession.ts","../src/composables/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\n\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './composables';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useForgotPassword(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst sent = ref(false);\n\n\tasync function forgotPassword(email: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.forgotPassword(email);\n\t\t\tsent.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useLogin(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<ILoginResult | null>(null);\n\n\tasync function login(input: ILoginInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.login(input);\n\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { login, isLoading, error, data };\n}\n","export const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\tlocalStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\tlocalStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken(): string | null {\n\treturn localStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { clearToken } from '../storage';\n\nexport function useLogout(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\n\tasync function logout() {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t} finally {\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useRegister(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IRegisterResult | null>(null);\n\n\tasync function register(input: IRegisterInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.register(input);\n\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useResetPassword(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst done = ref(false);\n\n\tasync function resetPassword(input: IResetPasswordInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.resetPassword(input);\n\t\t\tdone.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { clearToken, readToken } from '../storage';\n\nexport function useSession(client: AuthClient) {\n\tconst user = ref<IUserDTO | null>(null);\n\tconst isLoading = ref(true);\n\tconst isAuthenticated = ref(false);\n\n\tasync function refresh() {\n\t\tisLoading.value = true;\n\t\ttry {\n\t\t\tconst { result } = await client.getUser();\n\t\t\tuser.value = result.user;\n\t\t\tisAuthenticated.value = true;\n\t\t} catch {\n\t\t\tuser.value = null;\n\t\t\tisAuthenticated.value = false;\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\tasync function logout() {\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tclient.setAccessToken(undefined);\n\t\tclearToken();\n\t\tuser.value = null;\n\t\tisAuthenticated.value = false;\n\t}\n\n\tconst token = readToken();\n\tif (token) client.setAccessToken(token);\n\tvoid refresh();\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useVerifyEmail(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IVerifyEmailResult | null>(null);\n\n\tasync function verifyEmail(pin: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.verifyEmail(pin);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\ter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D,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,iBAAe,SAAS;AACvB,QAAI;AACH,YAAM,OAAO,OAAO;AAAA,IACrB,QAAQ;AAAA,IAER;AACA,WAAO,eAAe,MAAS;AAC/B,eAAW;AACX,SAAK,QAAQ;AACb,oBAAgB,QAAQ;AAAA,EACzB;AAEA,QAAM,QAAQ,UAAU;AACxB,MAAI,MAAO,QAAO,eAAe,KAAK;AACtC,OAAK,QAAQ;AAEb,SAAO,EAAE,MAAM,WAAW,iBAAiB,SAAS,OAAO;AAC5D;;;ACzCA,IAAAC,iBAAiC;AACjC,IAAAC,cAAoB;AAEb,SAAS,eAAe,QAAoB;AAClD,QAAM,gBAAY,iBAAI,KAAK;AAC3B,QAAM,YAAQ,iBAA6B,IAAI;AAC/C,QAAM,WAAO,iBAA+B,IAAI;AAEhD,iBAAe,YAAY,KAAa;AACvC,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,GAAG;AAC/C,WAAK,QAAQ;AACb,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,YAAM,QAAQ;AACd,YAAM;AAAA,IACP,UAAE;AACD,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["import_client","import_client","import_vue","import_client","import_vue","import_client","import_vue","import_client","import_vue","import_vue","import_client","import_vue"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/composables/useForgotPassword.ts","../src/composables/useLogin.ts","../src/storage.ts","../src/composables/useLogout.ts","../src/composables/useRegister.ts","../src/composables/useResetPassword.ts","../src/composables/useSession.ts","../src/composables/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\n\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './composables';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useForgotPassword(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useForgotPassword');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst sent = ref(false);\n\n\tasync function forgotPassword(email: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.forgotPassword(email);\n\t\t\tsent.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult, IMfaRequiredResult } from '@fonderie/client';\nimport { FonderieApiError, isMfaRequired } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useLogin(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogin');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<ILoginResult | null>(null);\n\t// Set when the account requires MFA: complete the login with\n\t// client.auth.mfa.verifyLogin(mfaPending.value.mfaToken, code).\n\tconst mfaPending = ref<IMfaRequiredResult | null>(null);\n\n\tasync function login(input: ILoginInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\tmfaPending.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.login(input);\n\t\t\tif (isMfaRequired(result)) {\n\t\t\t\tmfaPending.value = result;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { login, isLoading, error, data, mfaPending };\n}\n","export const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\tlocalStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\tlocalStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken(): string | null {\n\treturn localStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { clearToken } from '../storage';\n\nexport function useLogout(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogout');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\n\tasync function logout(refreshToken?: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t} finally {\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useRegister(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useRegister');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IRegisterResult | null>(null);\n\n\tasync function register(input: IRegisterInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.register(input);\n\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useResetPassword(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useResetPassword');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst done = ref(false);\n\n\tasync function resetPassword(input: IResetPasswordInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.resetPassword(input);\n\t\t\tdone.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { clearToken, readToken } from '../storage';\n\nexport function useSession(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useSession');\n\tconst user = ref<IUserDTO | null>(null);\n\tconst isLoading = ref(true);\n\tconst isAuthenticated = ref(false);\n\n\tasync function refresh() {\n\t\tisLoading.value = true;\n\t\ttry {\n\t\t\tconst { result } = await auth.getUser();\n\t\t\tuser.value = result.user;\n\t\t\tisAuthenticated.value = true;\n\t\t} catch {\n\t\t\tuser.value = null;\n\t\t\tisAuthenticated.value = false;\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\tasync function logout(refreshToken?: string) {\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tauth.setAccessToken(undefined);\n\t\tclearToken();\n\t\tuser.value = null;\n\t\tisAuthenticated.value = false;\n\t}\n\n\tconst token = readToken();\n\tif (token) auth.setAccessToken(token);\n\tvoid refresh();\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useVerifyEmail(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useVerifyEmail');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IVerifyEmailResult | null>(null);\n\n\tasync function verifyEmail(pin: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.verifyEmail(pin);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,IAAAA,iBAAiC;;;ACXjC,oBAAiC;AACjC,iBAAqC;AACrC,IAAAC,cAAoB;AAEb,SAAS,kBAAkB,QAAqB;AACtD,QAAM,WAAO,iCAAqB,QAAQ,CAAC,MAAM,EAAE,MAAM,mBAAmB;AAC5E,QAAM,gBAAY,iBAAI,KAAK;AAC3B,QAAM,YAAQ,iBAA6B,IAAI;AAC/C,QAAM,WAAO,iBAAI,KAAK;AAEtB,iBAAe,eAAe,OAAe;AAC5C,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACH,YAAM,KAAK,eAAe,KAAK;AAC/B,WAAK,QAAQ;AAAA,IACd,SAAS,KAAK;AACb,YAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,YAAM,QAAQ;AACd,YAAM;AAAA,IACP,UAAE;AACD,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,gBAAgB,WAAW,OAAO,KAAK;AACjD;;;AC3BA,IAAAC,iBAAgD;AAChD,IAAAC,cAAqC;AACrC,IAAAA,cAAoB;;;ACHb,IAAM,YAAY;AAElB,SAAS,aAAa,OAAe;AAC3C,eAAa,QAAQ,WAAW,KAAK;AACtC;AAEO,SAAS,aAAa;AAC5B,eAAa,WAAW,SAAS;AAClC;AAEO,SAAS,YAA2B;AAC1C,SAAO,aAAa,QAAQ,SAAS;AACtC;;;ADNO,SAAS,SAAS,QAAqB;AAC7C,QAA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,CAAC,MAAM,EAAE,MAAM,gBAAgB;AACzE,QAAM,gBAAY,kBAAI,KAAK;AAC3B,QAAM,YAAQ,kBAA6B,IAAI;AAC/C,QAAM,WAAO,kBAA+B,IAAI;AAEhD,iBAAe,YAAY,KAAa;AACvC,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,KAAK,YAAY,GAAG;AAC7C,WAAK,QAAQ;AACb,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,YAAM,QAAQ;AACd,YAAM;AAAA,IACP,UAAE;AACD,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["import_client","import_vue","import_client","import_vue","import_client","import_vue","import_client","import_vue","import_client","import_vue","import_vue","import_client","import_vue"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
1
|
+
import { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
2
|
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
|
|
5
|
-
declare function useForgotPassword(client
|
|
5
|
+
declare function useForgotPassword(client?: AuthClient): {
|
|
6
6
|
forgotPassword: (email: string) => Promise<void>;
|
|
7
7
|
isLoading: vue.Ref<boolean, boolean>;
|
|
8
8
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
9
9
|
sent: vue.Ref<boolean, boolean>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
declare function useLogin(client
|
|
13
|
-
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
12
|
+
declare function useLogin(client?: AuthClient): {
|
|
13
|
+
login: (input: ILoginInput) => Promise<ILoginResult | IMfaRequiredResult>;
|
|
14
14
|
isLoading: vue.Ref<boolean, boolean>;
|
|
15
15
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
16
16
|
data: vue.Ref<{
|
|
@@ -92,15 +92,20 @@ declare function useLogin(client: AuthClient): {
|
|
|
92
92
|
updatedAt: string;
|
|
93
93
|
};
|
|
94
94
|
} | null>;
|
|
95
|
+
mfaPending: vue.Ref<{
|
|
96
|
+
mfaToken: string;
|
|
97
|
+
} | null, IMfaRequiredResult | {
|
|
98
|
+
mfaToken: string;
|
|
99
|
+
} | null>;
|
|
95
100
|
};
|
|
96
101
|
|
|
97
|
-
declare function useLogout(client
|
|
98
|
-
logout: () => Promise<void>;
|
|
102
|
+
declare function useLogout(client?: AuthClient): {
|
|
103
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
99
104
|
isLoading: vue.Ref<boolean, boolean>;
|
|
100
105
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
101
106
|
};
|
|
102
107
|
|
|
103
|
-
declare function useRegister(client
|
|
108
|
+
declare function useRegister(client?: AuthClient): {
|
|
104
109
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
105
110
|
isLoading: vue.Ref<boolean, boolean>;
|
|
106
111
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
@@ -185,14 +190,14 @@ declare function useRegister(client: AuthClient): {
|
|
|
185
190
|
} | null>;
|
|
186
191
|
};
|
|
187
192
|
|
|
188
|
-
declare function useResetPassword(client
|
|
193
|
+
declare function useResetPassword(client?: AuthClient): {
|
|
189
194
|
resetPassword: (input: IResetPasswordInput) => Promise<void>;
|
|
190
195
|
isLoading: vue.Ref<boolean, boolean>;
|
|
191
196
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
192
197
|
done: vue.Ref<boolean, boolean>;
|
|
193
198
|
};
|
|
194
199
|
|
|
195
|
-
declare function useSession(client
|
|
200
|
+
declare function useSession(client?: AuthClient): {
|
|
196
201
|
user: vue.Ref<{
|
|
197
202
|
id: string;
|
|
198
203
|
email: string;
|
|
@@ -263,10 +268,10 @@ declare function useSession(client: AuthClient): {
|
|
|
263
268
|
isLoading: vue.Ref<boolean, boolean>;
|
|
264
269
|
isAuthenticated: vue.Ref<boolean, boolean>;
|
|
265
270
|
refresh: () => Promise<void>;
|
|
266
|
-
logout: () => Promise<void>;
|
|
271
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
267
272
|
};
|
|
268
273
|
|
|
269
|
-
declare function useVerifyEmail(client
|
|
274
|
+
declare function useVerifyEmail(client?: AuthClient): {
|
|
270
275
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
271
276
|
isLoading: vue.Ref<boolean, boolean>;
|
|
272
277
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
1
|
+
import { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
2
|
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
|
|
5
|
-
declare function useForgotPassword(client
|
|
5
|
+
declare function useForgotPassword(client?: AuthClient): {
|
|
6
6
|
forgotPassword: (email: string) => Promise<void>;
|
|
7
7
|
isLoading: vue.Ref<boolean, boolean>;
|
|
8
8
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
9
9
|
sent: vue.Ref<boolean, boolean>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
declare function useLogin(client
|
|
13
|
-
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
12
|
+
declare function useLogin(client?: AuthClient): {
|
|
13
|
+
login: (input: ILoginInput) => Promise<ILoginResult | IMfaRequiredResult>;
|
|
14
14
|
isLoading: vue.Ref<boolean, boolean>;
|
|
15
15
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
16
16
|
data: vue.Ref<{
|
|
@@ -92,15 +92,20 @@ declare function useLogin(client: AuthClient): {
|
|
|
92
92
|
updatedAt: string;
|
|
93
93
|
};
|
|
94
94
|
} | null>;
|
|
95
|
+
mfaPending: vue.Ref<{
|
|
96
|
+
mfaToken: string;
|
|
97
|
+
} | null, IMfaRequiredResult | {
|
|
98
|
+
mfaToken: string;
|
|
99
|
+
} | null>;
|
|
95
100
|
};
|
|
96
101
|
|
|
97
|
-
declare function useLogout(client
|
|
98
|
-
logout: () => Promise<void>;
|
|
102
|
+
declare function useLogout(client?: AuthClient): {
|
|
103
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
99
104
|
isLoading: vue.Ref<boolean, boolean>;
|
|
100
105
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
101
106
|
};
|
|
102
107
|
|
|
103
|
-
declare function useRegister(client
|
|
108
|
+
declare function useRegister(client?: AuthClient): {
|
|
104
109
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
105
110
|
isLoading: vue.Ref<boolean, boolean>;
|
|
106
111
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
@@ -185,14 +190,14 @@ declare function useRegister(client: AuthClient): {
|
|
|
185
190
|
} | null>;
|
|
186
191
|
};
|
|
187
192
|
|
|
188
|
-
declare function useResetPassword(client
|
|
193
|
+
declare function useResetPassword(client?: AuthClient): {
|
|
189
194
|
resetPassword: (input: IResetPasswordInput) => Promise<void>;
|
|
190
195
|
isLoading: vue.Ref<boolean, boolean>;
|
|
191
196
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
192
197
|
done: vue.Ref<boolean, boolean>;
|
|
193
198
|
};
|
|
194
199
|
|
|
195
|
-
declare function useSession(client
|
|
200
|
+
declare function useSession(client?: AuthClient): {
|
|
196
201
|
user: vue.Ref<{
|
|
197
202
|
id: string;
|
|
198
203
|
email: string;
|
|
@@ -263,10 +268,10 @@ declare function useSession(client: AuthClient): {
|
|
|
263
268
|
isLoading: vue.Ref<boolean, boolean>;
|
|
264
269
|
isAuthenticated: vue.Ref<boolean, boolean>;
|
|
265
270
|
refresh: () => Promise<void>;
|
|
266
|
-
logout: () => Promise<void>;
|
|
271
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
267
272
|
};
|
|
268
273
|
|
|
269
|
-
declare function useVerifyEmail(client
|
|
274
|
+
declare function useVerifyEmail(client?: AuthClient): {
|
|
270
275
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
271
276
|
isLoading: vue.Ref<boolean, boolean>;
|
|
272
277
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import { FonderieApiError as FonderieApiError7 } from "@fonderie/client";
|
|
|
3
3
|
|
|
4
4
|
// src/composables/useForgotPassword.ts
|
|
5
5
|
import { FonderieApiError } from "@fonderie/client";
|
|
6
|
+
import { useFonderieSubClient } from "@fonderie/vue";
|
|
6
7
|
import { ref } from "vue";
|
|
7
8
|
function useForgotPassword(client) {
|
|
9
|
+
const auth = useFonderieSubClient(client, (c) => c.auth, "useForgotPassword");
|
|
8
10
|
const isLoading = ref(false);
|
|
9
11
|
const error = ref(null);
|
|
10
12
|
const sent = ref(false);
|
|
@@ -12,7 +14,7 @@ function useForgotPassword(client) {
|
|
|
12
14
|
isLoading.value = true;
|
|
13
15
|
error.value = null;
|
|
14
16
|
try {
|
|
15
|
-
await
|
|
17
|
+
await auth.forgotPassword(email);
|
|
16
18
|
sent.value = true;
|
|
17
19
|
} catch (err) {
|
|
18
20
|
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
@@ -26,7 +28,8 @@ function useForgotPassword(client) {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
// src/composables/useLogin.ts
|
|
29
|
-
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
31
|
+
import { FonderieApiError as FonderieApiError2, isMfaRequired } from "@fonderie/client";
|
|
32
|
+
import { useFonderieSubClient as useFonderieSubClient2 } from "@fonderie/vue";
|
|
30
33
|
import { ref as ref2 } from "vue";
|
|
31
34
|
|
|
32
35
|
// src/storage.ts
|
|
@@ -43,15 +46,22 @@ function readToken() {
|
|
|
43
46
|
|
|
44
47
|
// src/composables/useLogin.ts
|
|
45
48
|
function useLogin(client) {
|
|
49
|
+
const auth = useFonderieSubClient2(client, (c) => c.auth, "useLogin");
|
|
46
50
|
const isLoading = ref2(false);
|
|
47
51
|
const error = ref2(null);
|
|
48
52
|
const data = ref2(null);
|
|
53
|
+
const mfaPending = ref2(null);
|
|
49
54
|
async function login(input) {
|
|
50
55
|
isLoading.value = true;
|
|
51
56
|
error.value = null;
|
|
57
|
+
mfaPending.value = null;
|
|
52
58
|
try {
|
|
53
|
-
const { result } = await
|
|
54
|
-
|
|
59
|
+
const { result } = await auth.login(input);
|
|
60
|
+
if (isMfaRequired(result)) {
|
|
61
|
+
mfaPending.value = result;
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
auth.setAccessToken(result.tokens.access);
|
|
55
65
|
persistToken(result.tokens.access);
|
|
56
66
|
data.value = result;
|
|
57
67
|
return result;
|
|
@@ -63,25 +73,27 @@ function useLogin(client) {
|
|
|
63
73
|
isLoading.value = false;
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
|
-
return { login, isLoading, error, data };
|
|
76
|
+
return { login, isLoading, error, data, mfaPending };
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
// src/composables/useLogout.ts
|
|
70
80
|
import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
81
|
+
import { useFonderieSubClient as useFonderieSubClient3 } from "@fonderie/vue";
|
|
71
82
|
import { ref as ref3 } from "vue";
|
|
72
83
|
function useLogout(client) {
|
|
84
|
+
const auth = useFonderieSubClient3(client, (c) => c.auth, "useLogout");
|
|
73
85
|
const isLoading = ref3(false);
|
|
74
86
|
const error = ref3(null);
|
|
75
|
-
async function logout() {
|
|
87
|
+
async function logout(refreshToken) {
|
|
76
88
|
isLoading.value = true;
|
|
77
89
|
error.value = null;
|
|
78
90
|
try {
|
|
79
|
-
await
|
|
91
|
+
await auth.logout(refreshToken);
|
|
80
92
|
} catch (err) {
|
|
81
93
|
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
82
94
|
error.value = apiError;
|
|
83
95
|
} finally {
|
|
84
|
-
|
|
96
|
+
auth.setAccessToken(void 0);
|
|
85
97
|
clearToken();
|
|
86
98
|
isLoading.value = false;
|
|
87
99
|
}
|
|
@@ -91,8 +103,10 @@ function useLogout(client) {
|
|
|
91
103
|
|
|
92
104
|
// src/composables/useRegister.ts
|
|
93
105
|
import { FonderieApiError as FonderieApiError4 } from "@fonderie/client";
|
|
106
|
+
import { useFonderieSubClient as useFonderieSubClient4 } from "@fonderie/vue";
|
|
94
107
|
import { ref as ref4 } from "vue";
|
|
95
108
|
function useRegister(client) {
|
|
109
|
+
const auth = useFonderieSubClient4(client, (c) => c.auth, "useRegister");
|
|
96
110
|
const isLoading = ref4(false);
|
|
97
111
|
const error = ref4(null);
|
|
98
112
|
const data = ref4(null);
|
|
@@ -100,8 +114,8 @@ function useRegister(client) {
|
|
|
100
114
|
isLoading.value = true;
|
|
101
115
|
error.value = null;
|
|
102
116
|
try {
|
|
103
|
-
const { result } = await
|
|
104
|
-
|
|
117
|
+
const { result } = await auth.register(input);
|
|
118
|
+
auth.setAccessToken(result.tokens.access);
|
|
105
119
|
persistToken(result.tokens.access);
|
|
106
120
|
data.value = result;
|
|
107
121
|
return result;
|
|
@@ -118,8 +132,10 @@ function useRegister(client) {
|
|
|
118
132
|
|
|
119
133
|
// src/composables/useResetPassword.ts
|
|
120
134
|
import { FonderieApiError as FonderieApiError5 } from "@fonderie/client";
|
|
135
|
+
import { useFonderieSubClient as useFonderieSubClient5 } from "@fonderie/vue";
|
|
121
136
|
import { ref as ref5 } from "vue";
|
|
122
137
|
function useResetPassword(client) {
|
|
138
|
+
const auth = useFonderieSubClient5(client, (c) => c.auth, "useResetPassword");
|
|
123
139
|
const isLoading = ref5(false);
|
|
124
140
|
const error = ref5(null);
|
|
125
141
|
const done = ref5(false);
|
|
@@ -127,7 +143,7 @@ function useResetPassword(client) {
|
|
|
127
143
|
isLoading.value = true;
|
|
128
144
|
error.value = null;
|
|
129
145
|
try {
|
|
130
|
-
await
|
|
146
|
+
await auth.resetPassword(input);
|
|
131
147
|
done.value = true;
|
|
132
148
|
} catch (err) {
|
|
133
149
|
const apiError = err instanceof FonderieApiError5 ? err : new FonderieApiError5("unknown", String(err), 0);
|
|
@@ -141,46 +157,50 @@ function useResetPassword(client) {
|
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
// src/composables/useSession.ts
|
|
160
|
+
import { useFonderieSubClient as useFonderieSubClient6 } from "@fonderie/vue";
|
|
144
161
|
import { ref as ref6 } from "vue";
|
|
145
162
|
function useSession(client) {
|
|
163
|
+
const auth = useFonderieSubClient6(client, (c) => c.auth, "useSession");
|
|
146
164
|
const user = ref6(null);
|
|
147
165
|
const isLoading = ref6(true);
|
|
148
166
|
const isAuthenticated = ref6(false);
|
|
149
167
|
async function refresh() {
|
|
150
168
|
isLoading.value = true;
|
|
151
169
|
try {
|
|
152
|
-
const { result } = await
|
|
170
|
+
const { result } = await auth.getUser();
|
|
153
171
|
user.value = result.user;
|
|
154
172
|
isAuthenticated.value = true;
|
|
155
173
|
} catch {
|
|
156
174
|
user.value = null;
|
|
157
175
|
isAuthenticated.value = false;
|
|
158
|
-
|
|
176
|
+
auth.setAccessToken(void 0);
|
|
159
177
|
clearToken();
|
|
160
178
|
} finally {
|
|
161
179
|
isLoading.value = false;
|
|
162
180
|
}
|
|
163
181
|
}
|
|
164
|
-
async function logout() {
|
|
182
|
+
async function logout(refreshToken) {
|
|
165
183
|
try {
|
|
166
|
-
await
|
|
184
|
+
await auth.logout(refreshToken);
|
|
167
185
|
} catch {
|
|
168
186
|
}
|
|
169
|
-
|
|
187
|
+
auth.setAccessToken(void 0);
|
|
170
188
|
clearToken();
|
|
171
189
|
user.value = null;
|
|
172
190
|
isAuthenticated.value = false;
|
|
173
191
|
}
|
|
174
192
|
const token = readToken();
|
|
175
|
-
if (token)
|
|
193
|
+
if (token) auth.setAccessToken(token);
|
|
176
194
|
void refresh();
|
|
177
195
|
return { user, isLoading, isAuthenticated, refresh, logout };
|
|
178
196
|
}
|
|
179
197
|
|
|
180
198
|
// src/composables/useVerifyEmail.ts
|
|
181
199
|
import { FonderieApiError as FonderieApiError6 } from "@fonderie/client";
|
|
200
|
+
import { useFonderieSubClient as useFonderieSubClient7 } from "@fonderie/vue";
|
|
182
201
|
import { ref as ref7 } from "vue";
|
|
183
202
|
function useVerifyEmail(client) {
|
|
203
|
+
const auth = useFonderieSubClient7(client, (c) => c.auth, "useVerifyEmail");
|
|
184
204
|
const isLoading = ref7(false);
|
|
185
205
|
const error = ref7(null);
|
|
186
206
|
const data = ref7(null);
|
|
@@ -188,7 +208,7 @@ function useVerifyEmail(client) {
|
|
|
188
208
|
isLoading.value = true;
|
|
189
209
|
error.value = null;
|
|
190
210
|
try {
|
|
191
|
-
const { result } = await
|
|
211
|
+
const { result } = await auth.verifyEmail(pin);
|
|
192
212
|
data.value = result;
|
|
193
213
|
return result;
|
|
194
214
|
} catch (err) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/composables/useForgotPassword.ts","../src/composables/useLogin.ts","../src/storage.ts","../src/composables/useLogout.ts","../src/composables/useRegister.ts","../src/composables/useResetPassword.ts","../src/composables/useSession.ts","../src/composables/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\n\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './composables';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useForgotPassword(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst sent = ref(false);\n\n\tasync function forgotPassword(email: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.forgotPassword(email);\n\t\t\tsent.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useLogin(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<ILoginResult | null>(null);\n\n\tasync function login(input: ILoginInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.login(input);\n\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { login, isLoading, error, data };\n}\n","export const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\tlocalStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\tlocalStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken(): string | null {\n\treturn localStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { clearToken } from '../storage';\n\nexport function useLogout(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\n\tasync function logout() {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t} finally {\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useRegister(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IRegisterResult | null>(null);\n\n\tasync function register(input: IRegisterInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.register(input);\n\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useResetPassword(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst done = ref(false);\n\n\tasync function resetPassword(input: IResetPasswordInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait client.resetPassword(input);\n\t\t\tdone.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { ref } from 'vue';\nimport { clearToken, readToken } from '../storage';\n\nexport function useSession(client: AuthClient) {\n\tconst user = ref<IUserDTO | null>(null);\n\tconst isLoading = ref(true);\n\tconst isAuthenticated = ref(false);\n\n\tasync function refresh() {\n\t\tisLoading.value = true;\n\t\ttry {\n\t\t\tconst { result } = await client.getUser();\n\t\t\tuser.value = result.user;\n\t\t\tisAuthenticated.value = true;\n\t\t} catch {\n\t\t\tuser.value = null;\n\t\t\tisAuthenticated.value = false;\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\tasync function logout() {\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tclient.setAccessToken(undefined);\n\t\tclearToken();\n\t\tuser.value = null;\n\t\tisAuthenticated.value = false;\n\t}\n\n\tconst token = readToken();\n\tif (token) client.setAccessToken(token);\n\tvoid refresh();\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { ref } from 'vue';\n\nexport function useVerifyEmail(client: AuthClient) {\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IVerifyEmailResult | null>(null);\n\n\tasync function verifyEmail(pin: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await client.verifyEmail(pin);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";AAYA,SAAS,oBAAAA,yBAAwB;;;ACXjC,SAAS,wBAAwB;AACjC,SAAS,WAAW;AAEb,SAAS,kBAAkB,QAAoB;AACrD,QAAM,YAAY,IAAI,KAAK;AAC3B,QAAM,QAAQ,IAA6B,IAAI;AAC/C,QAAM,OAAO,IAAI,KAAK;AAEtB,iBAAe,eAAe,OAAe;AAC5C,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACH,YAAM,OAA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,QAAM,YAAYA,KAAI,KAAK;AAC3B,QAAM,QAAQA,KAA6B,IAAI;AAC/C,QAAM,OAAOA,KAA+B,IAAI;AAEhD,iBAAe,YAAY,KAAa;AACvC,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,GAAG;AAC/C,WAAK,QAAQ;AACb,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,WACL,eAAeD,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,YAAM,QAAQ;AACd,YAAM;AAAA,IACP,UAAE;AACD,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["FonderieApiError","FonderieApiError","ref","ref","FonderieApiError","FonderieApiError","ref","ref","FonderieApiError","FonderieApiError","ref","ref","FonderieApiError","FonderieApiError","ref","ref","ref","FonderieApiError","ref"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/composables/useForgotPassword.ts","../src/composables/useLogin.ts","../src/storage.ts","../src/composables/useLogout.ts","../src/composables/useRegister.ts","../src/composables/useResetPassword.ts","../src/composables/useSession.ts","../src/composables/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\n\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './composables';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useForgotPassword(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useForgotPassword');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst sent = ref(false);\n\n\tasync function forgotPassword(email: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.forgotPassword(email);\n\t\t\tsent.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult, IMfaRequiredResult } from '@fonderie/client';\nimport { FonderieApiError, isMfaRequired } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useLogin(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogin');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<ILoginResult | null>(null);\n\t// Set when the account requires MFA: complete the login with\n\t// client.auth.mfa.verifyLogin(mfaPending.value.mfaToken, code).\n\tconst mfaPending = ref<IMfaRequiredResult | null>(null);\n\n\tasync function login(input: ILoginInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\tmfaPending.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.login(input);\n\t\t\tif (isMfaRequired(result)) {\n\t\t\t\tmfaPending.value = result;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { login, isLoading, error, data, mfaPending };\n}\n","export const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\tlocalStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\tlocalStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken(): string | null {\n\treturn localStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { clearToken } from '../storage';\n\nexport function useLogout(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogout');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\n\tasync function logout(refreshToken?: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t} finally {\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { persistToken } from '../storage';\n\nexport function useRegister(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useRegister');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IRegisterResult | null>(null);\n\n\tasync function register(input: IRegisterInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.register(input);\n\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\tpersistToken(result.tokens.access);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useResetPassword(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useResetPassword');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst done = ref(false);\n\n\tasync function resetPassword(input: IResetPasswordInput) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tawait auth.resetPassword(input);\n\t\t\tdone.value = true;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\nimport { clearToken, readToken } from '../storage';\n\nexport function useSession(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useSession');\n\tconst user = ref<IUserDTO | null>(null);\n\tconst isLoading = ref(true);\n\tconst isAuthenticated = ref(false);\n\n\tasync function refresh() {\n\t\tisLoading.value = true;\n\t\ttry {\n\t\t\tconst { result } = await auth.getUser();\n\t\t\tuser.value = result.user;\n\t\t\tisAuthenticated.value = true;\n\t\t} catch {\n\t\t\tuser.value = null;\n\t\t\tisAuthenticated.value = false;\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tclearToken();\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\tasync function logout(refreshToken?: string) {\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tauth.setAccessToken(undefined);\n\t\tclearToken();\n\t\tuser.value = null;\n\t\tisAuthenticated.value = false;\n\t}\n\n\tconst token = readToken();\n\tif (token) auth.setAccessToken(token);\n\tvoid refresh();\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/vue';\nimport { ref } from 'vue';\n\nexport function useVerifyEmail(client?: AuthClient) {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useVerifyEmail');\n\tconst isLoading = ref(false);\n\tconst error = ref<FonderieApiError | null>(null);\n\tconst data = ref<IVerifyEmailResult | null>(null);\n\n\tasync function verifyEmail(pin: string) {\n\t\tisLoading.value = true;\n\t\terror.value = null;\n\t\ttry {\n\t\t\tconst { result } = await auth.verifyEmail(pin);\n\t\t\tdata.value = result;\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\terror.value = apiError;\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tisLoading.value = false;\n\t\t}\n\t}\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";AAYA,SAAS,oBAAAA,yBAAwB;;;ACXjC,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,WAAW;AAEb,SAAS,kBAAkB,QAAqB;AACtD,QAAM,OAAO,qBAAqB,QAAQ,CAAC,MAAM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AM,WACL,eAAeF,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,YAAM,QAAQ;AACd,YAAM;AAAA,IACP,UAAE;AACD,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["FonderieApiError","FonderieApiError","useFonderieSubClient","ref","useFonderieSubClient","ref","FonderieApiError","FonderieApiError","useFonderieSubClient","ref","useFonderieSubClient","ref","FonderieApiError","FonderieApiError","useFonderieSubClient","ref","useFonderieSubClient","ref","FonderieApiError","FonderieApiError","useFonderieSubClient","ref","useFonderieSubClient","ref","useFonderieSubClient","ref","FonderieApiError","useFonderieSubClient","ref"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/vue-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Vue composables for Fonderie auth — thin bindings over @fonderie/client.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"fonderiejs",
|
|
7
7
|
"vue",
|
|
8
8
|
"auth",
|
|
9
9
|
"composables",
|
|
@@ -28,19 +28,22 @@
|
|
|
28
28
|
"build": "tsup",
|
|
29
29
|
"dev": "tsup --watch",
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "tsx --test src/__tests__/*.test.ts",
|
|
31
32
|
"lint": "biome lint src",
|
|
32
33
|
"format": "biome format --write src",
|
|
33
34
|
"check": "biome check --write src"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@fonderie/client": "*"
|
|
37
|
+
"@fonderie/client": "*",
|
|
38
|
+
"@fonderie/vue": "*"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"vue": ">=3.0.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^26.2.0",
|
|
43
45
|
"tsup": "^8.5.1",
|
|
46
|
+
"tsx": "^4.21.0",
|
|
44
47
|
"typescript": "^6.0.3",
|
|
45
48
|
"vue": "^3.5.0"
|
|
46
49
|
},
|