@fonderie/vue-auth 0.5.0 → 0.6.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/dist/index.cjs +276 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +271 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { AuthClient,
|
|
2
|
-
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
1
|
+
import { FonderieApiError, AuthClient, IChangePasswordInput, ILoginInput, ILoginResult, IMfaRequiredResult, IMfaSetupResult, IMfaEnabledResult, IUserDTO, IUpdateProfileInput, IUpdatePreferencesInput, IRegisterInput, IRegisterResult, IResetPasswordInput, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
+
export { AuthClient, FonderieApiError, IChangePasswordInput, ILoginInput, ILoginResult, IMfaEnabledResult, IMfaRequiredResult, IMfaSetupResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUpdatePreferencesInput, IUpdateProfileInput, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { Ref } from 'vue';
|
|
5
5
|
|
|
6
|
+
interface IUseAccountDataReturn {
|
|
7
|
+
exportData: () => Promise<unknown>;
|
|
8
|
+
deleteUser: () => Promise<void>;
|
|
9
|
+
isLoading: Ref<boolean>;
|
|
10
|
+
error: Ref<FonderieApiError | null>;
|
|
11
|
+
}
|
|
12
|
+
declare function useAccountData(client?: AuthClient): IUseAccountDataReturn;
|
|
13
|
+
|
|
14
|
+
interface IUseChangePasswordReturn {
|
|
15
|
+
changePassword: (input: IChangePasswordInput) => Promise<void>;
|
|
16
|
+
isLoading: Ref<boolean>;
|
|
17
|
+
error: Ref<FonderieApiError | null>;
|
|
18
|
+
done: Ref<boolean>;
|
|
19
|
+
}
|
|
20
|
+
declare function useChangePassword(client?: AuthClient): IUseChangePasswordReturn;
|
|
21
|
+
|
|
6
22
|
declare function useForgotPassword(client?: AuthClient): {
|
|
7
23
|
forgotPassword: (email: string) => Promise<void>;
|
|
8
24
|
isLoading: vue.Ref<boolean, boolean>;
|
|
@@ -114,6 +130,29 @@ interface IUseMfaLoginReturn {
|
|
|
114
130
|
}
|
|
115
131
|
declare function useMfaLogin(client?: AuthClient): IUseMfaLoginReturn;
|
|
116
132
|
|
|
133
|
+
interface IUseMfaSetupReturn {
|
|
134
|
+
setup: () => Promise<IMfaSetupResult>;
|
|
135
|
+
setupData: Ref<IMfaSetupResult | null>;
|
|
136
|
+
verify: (code: string) => Promise<IMfaEnabledResult>;
|
|
137
|
+
disable: (code: string) => Promise<void>;
|
|
138
|
+
regenerateBackupCodes: (code: string) => Promise<string[]>;
|
|
139
|
+
isLoading: Ref<boolean>;
|
|
140
|
+
error: Ref<FonderieApiError | null>;
|
|
141
|
+
}
|
|
142
|
+
declare function useMfaSetup(client?: AuthClient): IUseMfaSetupReturn;
|
|
143
|
+
|
|
144
|
+
interface IUseProfileReturn {
|
|
145
|
+
user: Ref<IUserDTO | null>;
|
|
146
|
+
refresh: () => Promise<void>;
|
|
147
|
+
updateProfile: (input: IUpdateProfileInput) => Promise<IUserDTO>;
|
|
148
|
+
updatePreferences: (input: IUpdatePreferencesInput) => Promise<IUserDTO>;
|
|
149
|
+
updateEmail: (email: string) => Promise<void>;
|
|
150
|
+
updatePhone: (phone: string) => Promise<void>;
|
|
151
|
+
isLoading: Ref<boolean>;
|
|
152
|
+
error: Ref<FonderieApiError | null>;
|
|
153
|
+
}
|
|
154
|
+
declare function useProfile(client?: AuthClient): IUseProfileReturn;
|
|
155
|
+
|
|
117
156
|
declare function useRegister(client?: AuthClient): {
|
|
118
157
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
119
158
|
isLoading: vue.Ref<boolean, boolean>;
|
|
@@ -282,6 +321,8 @@ declare function useSession(client?: AuthClient): {
|
|
|
282
321
|
|
|
283
322
|
declare function useVerifyEmail(client?: AuthClient): {
|
|
284
323
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
324
|
+
resend: () => Promise<void>;
|
|
325
|
+
resent: vue.Ref<boolean, boolean>;
|
|
285
326
|
isLoading: vue.Ref<boolean, boolean>;
|
|
286
327
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
287
328
|
data: vue.Ref<{
|
|
@@ -298,4 +339,4 @@ declare function persistToken(token: string): void;
|
|
|
298
339
|
declare function clearToken(): void;
|
|
299
340
|
declare function readToken(): string | null;
|
|
300
341
|
|
|
301
|
-
export { type IUseMfaLoginReturn, TOKEN_KEY, clearToken, persistToken, readToken, useForgotPassword, useLogin, useLogout, useMfaLogin, useRegister, useResetPassword, useSession, useVerifyEmail };
|
|
342
|
+
export { type IUseAccountDataReturn, type IUseChangePasswordReturn, type IUseMfaLoginReturn, type IUseMfaSetupReturn, type IUseProfileReturn, TOKEN_KEY, clearToken, persistToken, readToken, useAccountData, useChangePassword, useForgotPassword, useLogin, useLogout, useMfaLogin, useMfaSetup, useProfile, useRegister, useResetPassword, useSession, useVerifyEmail };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { AuthClient,
|
|
2
|
-
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
1
|
+
import { FonderieApiError, AuthClient, IChangePasswordInput, ILoginInput, ILoginResult, IMfaRequiredResult, IMfaSetupResult, IMfaEnabledResult, IUserDTO, IUpdateProfileInput, IUpdatePreferencesInput, IRegisterInput, IRegisterResult, IResetPasswordInput, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
+
export { AuthClient, FonderieApiError, IChangePasswordInput, ILoginInput, ILoginResult, IMfaEnabledResult, IMfaRequiredResult, IMfaSetupResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUpdatePreferencesInput, IUpdateProfileInput, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { Ref } from 'vue';
|
|
5
5
|
|
|
6
|
+
interface IUseAccountDataReturn {
|
|
7
|
+
exportData: () => Promise<unknown>;
|
|
8
|
+
deleteUser: () => Promise<void>;
|
|
9
|
+
isLoading: Ref<boolean>;
|
|
10
|
+
error: Ref<FonderieApiError | null>;
|
|
11
|
+
}
|
|
12
|
+
declare function useAccountData(client?: AuthClient): IUseAccountDataReturn;
|
|
13
|
+
|
|
14
|
+
interface IUseChangePasswordReturn {
|
|
15
|
+
changePassword: (input: IChangePasswordInput) => Promise<void>;
|
|
16
|
+
isLoading: Ref<boolean>;
|
|
17
|
+
error: Ref<FonderieApiError | null>;
|
|
18
|
+
done: Ref<boolean>;
|
|
19
|
+
}
|
|
20
|
+
declare function useChangePassword(client?: AuthClient): IUseChangePasswordReturn;
|
|
21
|
+
|
|
6
22
|
declare function useForgotPassword(client?: AuthClient): {
|
|
7
23
|
forgotPassword: (email: string) => Promise<void>;
|
|
8
24
|
isLoading: vue.Ref<boolean, boolean>;
|
|
@@ -114,6 +130,29 @@ interface IUseMfaLoginReturn {
|
|
|
114
130
|
}
|
|
115
131
|
declare function useMfaLogin(client?: AuthClient): IUseMfaLoginReturn;
|
|
116
132
|
|
|
133
|
+
interface IUseMfaSetupReturn {
|
|
134
|
+
setup: () => Promise<IMfaSetupResult>;
|
|
135
|
+
setupData: Ref<IMfaSetupResult | null>;
|
|
136
|
+
verify: (code: string) => Promise<IMfaEnabledResult>;
|
|
137
|
+
disable: (code: string) => Promise<void>;
|
|
138
|
+
regenerateBackupCodes: (code: string) => Promise<string[]>;
|
|
139
|
+
isLoading: Ref<boolean>;
|
|
140
|
+
error: Ref<FonderieApiError | null>;
|
|
141
|
+
}
|
|
142
|
+
declare function useMfaSetup(client?: AuthClient): IUseMfaSetupReturn;
|
|
143
|
+
|
|
144
|
+
interface IUseProfileReturn {
|
|
145
|
+
user: Ref<IUserDTO | null>;
|
|
146
|
+
refresh: () => Promise<void>;
|
|
147
|
+
updateProfile: (input: IUpdateProfileInput) => Promise<IUserDTO>;
|
|
148
|
+
updatePreferences: (input: IUpdatePreferencesInput) => Promise<IUserDTO>;
|
|
149
|
+
updateEmail: (email: string) => Promise<void>;
|
|
150
|
+
updatePhone: (phone: string) => Promise<void>;
|
|
151
|
+
isLoading: Ref<boolean>;
|
|
152
|
+
error: Ref<FonderieApiError | null>;
|
|
153
|
+
}
|
|
154
|
+
declare function useProfile(client?: AuthClient): IUseProfileReturn;
|
|
155
|
+
|
|
117
156
|
declare function useRegister(client?: AuthClient): {
|
|
118
157
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
119
158
|
isLoading: vue.Ref<boolean, boolean>;
|
|
@@ -282,6 +321,8 @@ declare function useSession(client?: AuthClient): {
|
|
|
282
321
|
|
|
283
322
|
declare function useVerifyEmail(client?: AuthClient): {
|
|
284
323
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
324
|
+
resend: () => Promise<void>;
|
|
325
|
+
resent: vue.Ref<boolean, boolean>;
|
|
285
326
|
isLoading: vue.Ref<boolean, boolean>;
|
|
286
327
|
error: vue.Ref<FonderieApiError | null, FonderieApiError | null>;
|
|
287
328
|
data: vue.Ref<{
|
|
@@ -298,4 +339,4 @@ declare function persistToken(token: string): void;
|
|
|
298
339
|
declare function clearToken(): void;
|
|
299
340
|
declare function readToken(): string | null;
|
|
300
341
|
|
|
301
|
-
export { type IUseMfaLoginReturn, TOKEN_KEY, clearToken, persistToken, readToken, useForgotPassword, useLogin, useLogout, useMfaLogin, useRegister, useResetPassword, useSession, useVerifyEmail };
|
|
342
|
+
export { type IUseAccountDataReturn, type IUseChangePasswordReturn, type IUseMfaLoginReturn, type IUseMfaSetupReturn, type IUseProfileReturn, TOKEN_KEY, clearToken, persistToken, readToken, useAccountData, useChangePassword, useForgotPassword, useLogin, useLogout, useMfaLogin, useMfaSetup, useProfile, useRegister, useResetPassword, useSession, useVerifyEmail };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { FonderieApiError as
|
|
2
|
+
import { FonderieApiError as FonderieApiError12, isMfaRequired as isMfaRequired2 } from "@fonderie/client";
|
|
3
3
|
|
|
4
|
-
// src/composables/
|
|
4
|
+
// src/composables/useAccountData.ts
|
|
5
5
|
import { FonderieApiError } from "@fonderie/client";
|
|
6
6
|
import { useFonderieSubClient } from "@fonderie/vue";
|
|
7
7
|
import { ref } from "vue";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// src/storage.ts
|
|
10
|
+
var TOKEN_KEY = "fonderie_access_token";
|
|
11
|
+
function persistToken(token) {
|
|
12
|
+
localStorage.setItem(TOKEN_KEY, token);
|
|
13
|
+
}
|
|
14
|
+
function clearToken() {
|
|
15
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
16
|
+
}
|
|
17
|
+
function readToken() {
|
|
18
|
+
return localStorage.getItem(TOKEN_KEY);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/composables/useAccountData.ts
|
|
22
|
+
function useAccountData(client) {
|
|
23
|
+
const auth = useFonderieSubClient(client, (c) => c.auth, "useAccountData");
|
|
10
24
|
const isLoading = ref(false);
|
|
11
25
|
const error = ref(null);
|
|
12
|
-
|
|
13
|
-
async function forgotPassword(email) {
|
|
26
|
+
async function run(op) {
|
|
14
27
|
isLoading.value = true;
|
|
15
28
|
error.value = null;
|
|
16
29
|
try {
|
|
17
|
-
await
|
|
18
|
-
sent.value = true;
|
|
30
|
+
return await op();
|
|
19
31
|
} catch (err) {
|
|
20
32
|
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
21
33
|
error.value = apiError;
|
|
@@ -24,33 +36,85 @@ function useForgotPassword(client) {
|
|
|
24
36
|
isLoading.value = false;
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
|
-
|
|
39
|
+
function exportData() {
|
|
40
|
+
return run(async () => {
|
|
41
|
+
const { result } = await auth.exportData();
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function deleteUser() {
|
|
46
|
+
return run(async () => {
|
|
47
|
+
await auth.deleteUser();
|
|
48
|
+
auth.setAccessToken(void 0);
|
|
49
|
+
clearToken();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { exportData, deleteUser, isLoading, error };
|
|
28
53
|
}
|
|
29
54
|
|
|
30
|
-
// src/composables/
|
|
31
|
-
import { FonderieApiError as FonderieApiError2
|
|
55
|
+
// src/composables/useChangePassword.ts
|
|
56
|
+
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
32
57
|
import { useFonderieSubClient as useFonderieSubClient2 } from "@fonderie/vue";
|
|
33
58
|
import { ref as ref2 } from "vue";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
function useChangePassword(client) {
|
|
60
|
+
const auth = useFonderieSubClient2(client, (c) => c.auth, "useChangePassword");
|
|
61
|
+
const isLoading = ref2(false);
|
|
62
|
+
const error = ref2(null);
|
|
63
|
+
const done = ref2(false);
|
|
64
|
+
async function changePassword(input) {
|
|
65
|
+
isLoading.value = true;
|
|
66
|
+
error.value = null;
|
|
67
|
+
done.value = false;
|
|
68
|
+
try {
|
|
69
|
+
await auth.changePassword(input);
|
|
70
|
+
done.value = true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
const apiError = err instanceof FonderieApiError2 ? err : new FonderieApiError2("unknown", String(err), 0);
|
|
73
|
+
error.value = apiError;
|
|
74
|
+
throw apiError;
|
|
75
|
+
} finally {
|
|
76
|
+
isLoading.value = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { changePassword, isLoading, error, done };
|
|
42
80
|
}
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
|
|
82
|
+
// src/composables/useForgotPassword.ts
|
|
83
|
+
import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
84
|
+
import { useFonderieSubClient as useFonderieSubClient3 } from "@fonderie/vue";
|
|
85
|
+
import { ref as ref3 } from "vue";
|
|
86
|
+
function useForgotPassword(client) {
|
|
87
|
+
const auth = useFonderieSubClient3(client, (c) => c.auth, "useForgotPassword");
|
|
88
|
+
const isLoading = ref3(false);
|
|
89
|
+
const error = ref3(null);
|
|
90
|
+
const sent = ref3(false);
|
|
91
|
+
async function forgotPassword(email) {
|
|
92
|
+
isLoading.value = true;
|
|
93
|
+
error.value = null;
|
|
94
|
+
try {
|
|
95
|
+
await auth.forgotPassword(email);
|
|
96
|
+
sent.value = true;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
99
|
+
error.value = apiError;
|
|
100
|
+
throw apiError;
|
|
101
|
+
} finally {
|
|
102
|
+
isLoading.value = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { forgotPassword, isLoading, error, sent };
|
|
45
106
|
}
|
|
46
107
|
|
|
47
108
|
// src/composables/useLogin.ts
|
|
109
|
+
import { FonderieApiError as FonderieApiError4, isMfaRequired } from "@fonderie/client";
|
|
110
|
+
import { useFonderieSubClient as useFonderieSubClient4 } from "@fonderie/vue";
|
|
111
|
+
import { ref as ref4 } from "vue";
|
|
48
112
|
function useLogin(client) {
|
|
49
|
-
const auth =
|
|
50
|
-
const isLoading =
|
|
51
|
-
const error =
|
|
52
|
-
const data =
|
|
53
|
-
const mfaPending =
|
|
113
|
+
const auth = useFonderieSubClient4(client, (c) => c.auth, "useLogin");
|
|
114
|
+
const isLoading = ref4(false);
|
|
115
|
+
const error = ref4(null);
|
|
116
|
+
const data = ref4(null);
|
|
117
|
+
const mfaPending = ref4(null);
|
|
54
118
|
async function login(input) {
|
|
55
119
|
isLoading.value = true;
|
|
56
120
|
error.value = null;
|
|
@@ -66,7 +130,7 @@ function useLogin(client) {
|
|
|
66
130
|
data.value = result;
|
|
67
131
|
return result;
|
|
68
132
|
} catch (err) {
|
|
69
|
-
const apiError = err instanceof
|
|
133
|
+
const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
|
|
70
134
|
error.value = apiError;
|
|
71
135
|
throw apiError;
|
|
72
136
|
} finally {
|
|
@@ -77,20 +141,20 @@ function useLogin(client) {
|
|
|
77
141
|
}
|
|
78
142
|
|
|
79
143
|
// src/composables/useLogout.ts
|
|
80
|
-
import { FonderieApiError as
|
|
81
|
-
import { useFonderieSubClient as
|
|
82
|
-
import { ref as
|
|
144
|
+
import { FonderieApiError as FonderieApiError5 } from "@fonderie/client";
|
|
145
|
+
import { useFonderieSubClient as useFonderieSubClient5 } from "@fonderie/vue";
|
|
146
|
+
import { ref as ref5 } from "vue";
|
|
83
147
|
function useLogout(client) {
|
|
84
|
-
const auth =
|
|
85
|
-
const isLoading =
|
|
86
|
-
const error =
|
|
148
|
+
const auth = useFonderieSubClient5(client, (c) => c.auth, "useLogout");
|
|
149
|
+
const isLoading = ref5(false);
|
|
150
|
+
const error = ref5(null);
|
|
87
151
|
async function logout(refreshToken) {
|
|
88
152
|
isLoading.value = true;
|
|
89
153
|
error.value = null;
|
|
90
154
|
try {
|
|
91
155
|
await auth.logout(refreshToken);
|
|
92
156
|
} catch (err) {
|
|
93
|
-
const apiError = err instanceof
|
|
157
|
+
const apiError = err instanceof FonderieApiError5 ? err : new FonderieApiError5("unknown", String(err), 0);
|
|
94
158
|
error.value = apiError;
|
|
95
159
|
} finally {
|
|
96
160
|
auth.setAccessToken(void 0);
|
|
@@ -102,14 +166,14 @@ function useLogout(client) {
|
|
|
102
166
|
}
|
|
103
167
|
|
|
104
168
|
// src/composables/useMfaLogin.ts
|
|
105
|
-
import { FonderieApiError as
|
|
106
|
-
import { useFonderieSubClient as
|
|
107
|
-
import { ref as
|
|
169
|
+
import { FonderieApiError as FonderieApiError6 } from "@fonderie/client";
|
|
170
|
+
import { useFonderieSubClient as useFonderieSubClient6 } from "@fonderie/vue";
|
|
171
|
+
import { ref as ref6 } from "vue";
|
|
108
172
|
function useMfaLogin(client) {
|
|
109
|
-
const auth =
|
|
110
|
-
const isLoading =
|
|
111
|
-
const error =
|
|
112
|
-
const data =
|
|
173
|
+
const auth = useFonderieSubClient6(client, (c) => c.auth, "useMfaLogin");
|
|
174
|
+
const isLoading = ref6(false);
|
|
175
|
+
const error = ref6(null);
|
|
176
|
+
const data = ref6(null);
|
|
113
177
|
async function verifyLogin(mfaToken, code) {
|
|
114
178
|
isLoading.value = true;
|
|
115
179
|
error.value = null;
|
|
@@ -120,7 +184,7 @@ function useMfaLogin(client) {
|
|
|
120
184
|
data.value = result;
|
|
121
185
|
return result;
|
|
122
186
|
} catch (err) {
|
|
123
|
-
const apiError = err instanceof
|
|
187
|
+
const apiError = err instanceof FonderieApiError6 ? err : new FonderieApiError6("unknown", String(err), 0);
|
|
124
188
|
error.value = apiError;
|
|
125
189
|
throw apiError;
|
|
126
190
|
} finally {
|
|
@@ -130,15 +194,128 @@ function useMfaLogin(client) {
|
|
|
130
194
|
return { verifyLogin, isLoading, error, data };
|
|
131
195
|
}
|
|
132
196
|
|
|
197
|
+
// src/composables/useMfaSetup.ts
|
|
198
|
+
import { FonderieApiError as FonderieApiError7 } from "@fonderie/client";
|
|
199
|
+
import { useFonderieSubClient as useFonderieSubClient7 } from "@fonderie/vue";
|
|
200
|
+
import { ref as ref7 } from "vue";
|
|
201
|
+
function useMfaSetup(client) {
|
|
202
|
+
const auth = useFonderieSubClient7(client, (c) => c.auth, "useMfaSetup");
|
|
203
|
+
const setupData = ref7(null);
|
|
204
|
+
const isLoading = ref7(false);
|
|
205
|
+
const error = ref7(null);
|
|
206
|
+
async function run(op) {
|
|
207
|
+
isLoading.value = true;
|
|
208
|
+
error.value = null;
|
|
209
|
+
try {
|
|
210
|
+
return await op();
|
|
211
|
+
} catch (err) {
|
|
212
|
+
const apiError = err instanceof FonderieApiError7 ? err : new FonderieApiError7("unknown", String(err), 0);
|
|
213
|
+
error.value = apiError;
|
|
214
|
+
throw apiError;
|
|
215
|
+
} finally {
|
|
216
|
+
isLoading.value = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function setup() {
|
|
220
|
+
return run(async () => {
|
|
221
|
+
const { result } = await auth.mfa.setup();
|
|
222
|
+
setupData.value = result;
|
|
223
|
+
return result;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function verify(code) {
|
|
227
|
+
return run(async () => {
|
|
228
|
+
const { result } = await auth.mfa.verify(code);
|
|
229
|
+
auth.setAccessToken(result.tokens.access);
|
|
230
|
+
persistToken(result.tokens.access);
|
|
231
|
+
return result;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function disable(code) {
|
|
235
|
+
return run(async () => {
|
|
236
|
+
await auth.mfa.disable(code);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function regenerateBackupCodes(code) {
|
|
240
|
+
return run(async () => {
|
|
241
|
+
const { result } = await auth.mfa.regenerateBackupCodes(code);
|
|
242
|
+
return result.backupCodes;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return { setup, setupData, verify, disable, regenerateBackupCodes, isLoading, error };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/composables/useProfile.ts
|
|
249
|
+
import { FonderieApiError as FonderieApiError8 } from "@fonderie/client";
|
|
250
|
+
import { useFonderieSubClient as useFonderieSubClient8 } from "@fonderie/vue";
|
|
251
|
+
import { ref as ref8 } from "vue";
|
|
252
|
+
function useProfile(client) {
|
|
253
|
+
const auth = useFonderieSubClient8(client, (c) => c.auth, "useProfile");
|
|
254
|
+
const user = ref8(null);
|
|
255
|
+
const isLoading = ref8(true);
|
|
256
|
+
const error = ref8(null);
|
|
257
|
+
async function refresh() {
|
|
258
|
+
isLoading.value = true;
|
|
259
|
+
error.value = null;
|
|
260
|
+
try {
|
|
261
|
+
const { result } = await auth.getUser();
|
|
262
|
+
user.value = result.user;
|
|
263
|
+
} catch (err) {
|
|
264
|
+
const apiError = err instanceof FonderieApiError8 ? err : new FonderieApiError8("unknown", String(err), 0);
|
|
265
|
+
error.value = apiError;
|
|
266
|
+
} finally {
|
|
267
|
+
isLoading.value = false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function mutate(op) {
|
|
271
|
+
error.value = null;
|
|
272
|
+
try {
|
|
273
|
+
return await op();
|
|
274
|
+
} catch (err) {
|
|
275
|
+
const apiError = err instanceof FonderieApiError8 ? err : new FonderieApiError8("unknown", String(err), 0);
|
|
276
|
+
error.value = apiError;
|
|
277
|
+
throw apiError;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function updateProfile(input) {
|
|
281
|
+
return mutate(async () => {
|
|
282
|
+
const { result } = await auth.updateProfile(input);
|
|
283
|
+
user.value = result.user;
|
|
284
|
+
return result.user;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function updatePreferences(input) {
|
|
288
|
+
return mutate(async () => {
|
|
289
|
+
const { result } = await auth.updatePreferences(input);
|
|
290
|
+
user.value = result.user;
|
|
291
|
+
return result.user;
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function updateEmail(email) {
|
|
295
|
+
return mutate(async () => {
|
|
296
|
+
await auth.updateEmail(email);
|
|
297
|
+
await refresh();
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function updatePhone(phone) {
|
|
301
|
+
return mutate(async () => {
|
|
302
|
+
await auth.updatePhone(phone);
|
|
303
|
+
await refresh();
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
void refresh();
|
|
307
|
+
return { user, refresh, updateProfile, updatePreferences, updateEmail, updatePhone, isLoading, error };
|
|
308
|
+
}
|
|
309
|
+
|
|
133
310
|
// src/composables/useRegister.ts
|
|
134
|
-
import { FonderieApiError as
|
|
135
|
-
import { useFonderieSubClient as
|
|
136
|
-
import { ref as
|
|
311
|
+
import { FonderieApiError as FonderieApiError9 } from "@fonderie/client";
|
|
312
|
+
import { useFonderieSubClient as useFonderieSubClient9 } from "@fonderie/vue";
|
|
313
|
+
import { ref as ref9 } from "vue";
|
|
137
314
|
function useRegister(client) {
|
|
138
|
-
const auth =
|
|
139
|
-
const isLoading =
|
|
140
|
-
const error =
|
|
141
|
-
const data =
|
|
315
|
+
const auth = useFonderieSubClient9(client, (c) => c.auth, "useRegister");
|
|
316
|
+
const isLoading = ref9(false);
|
|
317
|
+
const error = ref9(null);
|
|
318
|
+
const data = ref9(null);
|
|
142
319
|
async function register(input) {
|
|
143
320
|
isLoading.value = true;
|
|
144
321
|
error.value = null;
|
|
@@ -149,7 +326,7 @@ function useRegister(client) {
|
|
|
149
326
|
data.value = result;
|
|
150
327
|
return result;
|
|
151
328
|
} catch (err) {
|
|
152
|
-
const apiError = err instanceof
|
|
329
|
+
const apiError = err instanceof FonderieApiError9 ? err : new FonderieApiError9("unknown", String(err), 0);
|
|
153
330
|
error.value = apiError;
|
|
154
331
|
throw apiError;
|
|
155
332
|
} finally {
|
|
@@ -160,14 +337,14 @@ function useRegister(client) {
|
|
|
160
337
|
}
|
|
161
338
|
|
|
162
339
|
// src/composables/useResetPassword.ts
|
|
163
|
-
import { FonderieApiError as
|
|
164
|
-
import { useFonderieSubClient as
|
|
165
|
-
import { ref as
|
|
340
|
+
import { FonderieApiError as FonderieApiError10 } from "@fonderie/client";
|
|
341
|
+
import { useFonderieSubClient as useFonderieSubClient10 } from "@fonderie/vue";
|
|
342
|
+
import { ref as ref10 } from "vue";
|
|
166
343
|
function useResetPassword(client) {
|
|
167
|
-
const auth =
|
|
168
|
-
const isLoading =
|
|
169
|
-
const error =
|
|
170
|
-
const done =
|
|
344
|
+
const auth = useFonderieSubClient10(client, (c) => c.auth, "useResetPassword");
|
|
345
|
+
const isLoading = ref10(false);
|
|
346
|
+
const error = ref10(null);
|
|
347
|
+
const done = ref10(false);
|
|
171
348
|
async function resetPassword(input) {
|
|
172
349
|
isLoading.value = true;
|
|
173
350
|
error.value = null;
|
|
@@ -175,7 +352,7 @@ function useResetPassword(client) {
|
|
|
175
352
|
await auth.resetPassword(input);
|
|
176
353
|
done.value = true;
|
|
177
354
|
} catch (err) {
|
|
178
|
-
const apiError = err instanceof
|
|
355
|
+
const apiError = err instanceof FonderieApiError10 ? err : new FonderieApiError10("unknown", String(err), 0);
|
|
179
356
|
error.value = apiError;
|
|
180
357
|
throw apiError;
|
|
181
358
|
} finally {
|
|
@@ -186,13 +363,13 @@ function useResetPassword(client) {
|
|
|
186
363
|
}
|
|
187
364
|
|
|
188
365
|
// src/composables/useSession.ts
|
|
189
|
-
import { useFonderieSubClient as
|
|
190
|
-
import { ref as
|
|
366
|
+
import { useFonderieSubClient as useFonderieSubClient11 } from "@fonderie/vue";
|
|
367
|
+
import { ref as ref11 } from "vue";
|
|
191
368
|
function useSession(client) {
|
|
192
|
-
const auth =
|
|
193
|
-
const user =
|
|
194
|
-
const isLoading =
|
|
195
|
-
const isAuthenticated =
|
|
369
|
+
const auth = useFonderieSubClient11(client, (c) => c.auth, "useSession");
|
|
370
|
+
const user = ref11(null);
|
|
371
|
+
const isLoading = ref11(true);
|
|
372
|
+
const isAuthenticated = ref11(false);
|
|
196
373
|
async function refresh() {
|
|
197
374
|
isLoading.value = true;
|
|
198
375
|
try {
|
|
@@ -225,14 +402,30 @@ function useSession(client) {
|
|
|
225
402
|
}
|
|
226
403
|
|
|
227
404
|
// src/composables/useVerifyEmail.ts
|
|
228
|
-
import { FonderieApiError as
|
|
229
|
-
import { useFonderieSubClient as
|
|
230
|
-
import { ref as
|
|
405
|
+
import { FonderieApiError as FonderieApiError11 } from "@fonderie/client";
|
|
406
|
+
import { useFonderieSubClient as useFonderieSubClient12 } from "@fonderie/vue";
|
|
407
|
+
import { ref as ref12 } from "vue";
|
|
231
408
|
function useVerifyEmail(client) {
|
|
232
|
-
const auth =
|
|
233
|
-
const isLoading =
|
|
234
|
-
const error =
|
|
235
|
-
const data =
|
|
409
|
+
const auth = useFonderieSubClient12(client, (c) => c.auth, "useVerifyEmail");
|
|
410
|
+
const isLoading = ref12(false);
|
|
411
|
+
const error = ref12(null);
|
|
412
|
+
const data = ref12(null);
|
|
413
|
+
const resent = ref12(false);
|
|
414
|
+
async function resend() {
|
|
415
|
+
isLoading.value = true;
|
|
416
|
+
error.value = null;
|
|
417
|
+
resent.value = false;
|
|
418
|
+
try {
|
|
419
|
+
await auth.sendVerificationEmail();
|
|
420
|
+
resent.value = true;
|
|
421
|
+
} catch (err) {
|
|
422
|
+
const apiError = err instanceof FonderieApiError11 ? err : new FonderieApiError11("unknown", String(err), 0);
|
|
423
|
+
error.value = apiError;
|
|
424
|
+
throw apiError;
|
|
425
|
+
} finally {
|
|
426
|
+
isLoading.value = false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
236
429
|
async function verifyEmail(pin) {
|
|
237
430
|
isLoading.value = true;
|
|
238
431
|
error.value = null;
|
|
@@ -241,26 +434,30 @@ function useVerifyEmail(client) {
|
|
|
241
434
|
data.value = result;
|
|
242
435
|
return result;
|
|
243
436
|
} catch (err) {
|
|
244
|
-
const apiError = err instanceof
|
|
437
|
+
const apiError = err instanceof FonderieApiError11 ? err : new FonderieApiError11("unknown", String(err), 0);
|
|
245
438
|
error.value = apiError;
|
|
246
439
|
throw apiError;
|
|
247
440
|
} finally {
|
|
248
441
|
isLoading.value = false;
|
|
249
442
|
}
|
|
250
443
|
}
|
|
251
|
-
return { verifyEmail, isLoading, error, data };
|
|
444
|
+
return { verifyEmail, resend, resent, isLoading, error, data };
|
|
252
445
|
}
|
|
253
446
|
export {
|
|
254
|
-
|
|
447
|
+
FonderieApiError12 as FonderieApiError,
|
|
255
448
|
TOKEN_KEY,
|
|
256
449
|
clearToken,
|
|
257
450
|
isMfaRequired2 as isMfaRequired,
|
|
258
451
|
persistToken,
|
|
259
452
|
readToken,
|
|
453
|
+
useAccountData,
|
|
454
|
+
useChangePassword,
|
|
260
455
|
useForgotPassword,
|
|
261
456
|
useLogin,
|
|
262
457
|
useLogout,
|
|
263
458
|
useMfaLogin,
|
|
459
|
+
useMfaSetup,
|
|
460
|
+
useProfile,
|
|
264
461
|
useRegister,
|
|
265
462
|
useResetPassword,
|
|
266
463
|
useSession,
|