@bagelink/auth 1.1.41 → 1.1.43
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 +135 -201
- package/dist/index.d.cts +25 -29
- package/dist/index.d.mts +25 -29
- package/dist/index.d.ts +25 -29
- package/dist/index.mjs +135 -189
- package/package.json +13 -3
- package/src/api/auth.ts +81 -68
- package/src/composable/useAuth.ts +60 -126
- package/src/api/api.ts +0 -20
package/dist/index.cjs
CHANGED
|
@@ -6,181 +6,141 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
class AuthApi {
|
|
16
|
+
constructor(baseURL) {
|
|
17
|
+
__publicField(this, "api");
|
|
18
|
+
this.api = axios__default.create({
|
|
19
|
+
baseURL,
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json"
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
this.setupInterceptors();
|
|
13
25
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const token = localStorage.getItem("access_token");
|
|
28
|
-
if (token !== null && config.headers) {
|
|
29
|
-
config.headers.Authorization = `Bearer ${token}`;
|
|
26
|
+
setupInterceptors() {
|
|
27
|
+
this.api.interceptors.request.use((config) => {
|
|
28
|
+
const token = localStorage.getItem("access_token");
|
|
29
|
+
if (token !== null && config.headers) {
|
|
30
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
31
|
+
}
|
|
32
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
33
|
+
const resetToken = urlParams.get("token");
|
|
34
|
+
if (resetToken !== null && config.headers) {
|
|
35
|
+
config.headers.Authorization = `Bearer ${resetToken}`;
|
|
36
|
+
}
|
|
37
|
+
return config;
|
|
38
|
+
});
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
async login(username, password) {
|
|
41
|
+
const { data } = await this.api.post("/auth/login", {
|
|
42
|
+
username: username.toLowerCase(),
|
|
43
|
+
password
|
|
44
|
+
});
|
|
45
|
+
localStorage.setItem("access_token", data.access_token);
|
|
46
|
+
return { data };
|
|
47
|
+
}
|
|
48
|
+
logout() {
|
|
49
|
+
localStorage.removeItem("access_token");
|
|
50
|
+
window.location.reload();
|
|
51
|
+
}
|
|
52
|
+
async passwordRecovery(email) {
|
|
53
|
+
return this.api.post("/auth/password-recovery", { email });
|
|
54
|
+
}
|
|
55
|
+
async resetPassword(newPassword) {
|
|
56
|
+
return this.api.post("/auth/reset-password", { new_password: newPassword });
|
|
57
|
+
}
|
|
58
|
+
async getCurrentUser() {
|
|
59
|
+
return this.api.get("/users/me");
|
|
60
|
+
}
|
|
61
|
+
async signup(user) {
|
|
62
|
+
return this.api.post("/users/signup", {
|
|
63
|
+
email: user.email.toLowerCase(),
|
|
64
|
+
password: user.password,
|
|
65
|
+
first_name: user.first_name,
|
|
66
|
+
last_name: user.last_name
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async updatePassword(form) {
|
|
70
|
+
return this.api.patch("/users/me/password", {
|
|
71
|
+
current_password: form.current_password,
|
|
72
|
+
new_password: form.new_password
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async updateUserProfile(user) {
|
|
76
|
+
return this.api.patch("/users/me", user);
|
|
77
|
+
}
|
|
78
|
+
async setUserStatus(userId, isActive) {
|
|
79
|
+
return this.api.patch(`/users/${userId}`, { is_active: isActive });
|
|
80
|
+
}
|
|
81
|
+
async deleteUser(userId) {
|
|
82
|
+
return this.api.delete(`/users/${userId}`);
|
|
83
|
+
}
|
|
84
|
+
async getUsers(limit = 100, skip) {
|
|
85
|
+
return this.api.get("/users/", { params: { skip, limit } });
|
|
86
|
+
}
|
|
87
|
+
async createUser(user) {
|
|
88
|
+
return this.api.post("/users/", user);
|
|
89
|
+
}
|
|
90
|
+
async getUser(userId) {
|
|
91
|
+
return this.api.get(`/users/${userId}`);
|
|
35
92
|
}
|
|
36
|
-
return config;
|
|
37
|
-
});
|
|
38
|
-
async function login(username, password) {
|
|
39
|
-
const { data } = await ax.post("/auth/login", {
|
|
40
|
-
username: username.toLowerCase(),
|
|
41
|
-
password
|
|
42
|
-
});
|
|
43
|
-
localStorage.setItem("access_token", data.access_token);
|
|
44
|
-
return { data };
|
|
45
|
-
}
|
|
46
|
-
function logout() {
|
|
47
|
-
localStorage.removeItem("access_token");
|
|
48
|
-
window.location.reload();
|
|
49
|
-
}
|
|
50
|
-
async function passwordRecovery(email) {
|
|
51
|
-
return ax.post("/auth/password-recovery", { email });
|
|
52
|
-
}
|
|
53
|
-
async function resetPassword(newPassword) {
|
|
54
|
-
return ax.post("/auth/reset-password", { new_password: newPassword });
|
|
55
|
-
}
|
|
56
|
-
async function getCurrentUser() {
|
|
57
|
-
return ax.get("/users/me");
|
|
58
|
-
}
|
|
59
|
-
async function signup(user) {
|
|
60
|
-
return ax.post("/users/signup", {
|
|
61
|
-
email: user.email.toLowerCase(),
|
|
62
|
-
password: user.password,
|
|
63
|
-
first_name: user.first_name,
|
|
64
|
-
last_name: user.last_name
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
async function updatePassword(form) {
|
|
68
|
-
return ax.patch("/users/me/password", {
|
|
69
|
-
current_password: form.current_password,
|
|
70
|
-
new_password: form.new_password
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async function updateUserProfile(user) {
|
|
74
|
-
return ax.patch("/users/me", user);
|
|
75
|
-
}
|
|
76
|
-
async function setUserStatus(userId, isActive) {
|
|
77
|
-
return ax.patch(`/users/${userId}`, { is_active: isActive });
|
|
78
|
-
}
|
|
79
|
-
async function deleteUser(userId) {
|
|
80
|
-
return ax.delete(`/users/${userId}`);
|
|
81
|
-
}
|
|
82
|
-
async function getUsers(limit = 100, skip) {
|
|
83
|
-
return ax.get("/users/", { params: { skip, limit } });
|
|
84
|
-
}
|
|
85
|
-
async function createUser(user) {
|
|
86
|
-
return ax.post("/users/", user);
|
|
87
|
-
}
|
|
88
|
-
async function getUser(userId) {
|
|
89
|
-
return ax.get(`/users/${userId}`);
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
95
|
+
let authApi = null;
|
|
96
|
+
const currentUser = {
|
|
97
|
+
value: {
|
|
98
|
+
id: "",
|
|
99
|
+
email: "",
|
|
100
|
+
first_name: "",
|
|
101
|
+
last_name: "",
|
|
102
|
+
is_superuser: false,
|
|
103
|
+
is_active: false
|
|
104
|
+
},
|
|
105
|
+
set: (newValue) => {
|
|
106
|
+
currentUser.value = newValue;
|
|
107
|
+
}
|
|
105
108
|
};
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
get value() {
|
|
111
|
-
return refValue.value;
|
|
112
|
-
},
|
|
113
|
-
set: (v) => {
|
|
114
|
-
refValue.value = v;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function initAuth({
|
|
120
|
-
axios,
|
|
121
|
-
errorHandler,
|
|
122
|
-
reactive = defaultReactiveFactory,
|
|
123
|
-
baseURL
|
|
124
|
-
} = {}) {
|
|
125
|
-
api = axios || createDefaultApi(baseURL);
|
|
126
|
-
if (errorHandler)
|
|
127
|
-
onError = errorHandler;
|
|
128
|
-
createRef = reactive;
|
|
109
|
+
function initAuth(baseURL) {
|
|
110
|
+
if (!authApi) {
|
|
111
|
+
authApi = new AuthApi(baseURL);
|
|
112
|
+
}
|
|
129
113
|
return {
|
|
130
114
|
install(app) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
useAuth
|
|
115
|
+
app.config.globalProperties.$auth = useAuth();
|
|
116
|
+
}
|
|
136
117
|
};
|
|
137
118
|
}
|
|
138
119
|
function useAuth() {
|
|
139
|
-
if (!
|
|
140
|
-
throw new Error("Auth
|
|
120
|
+
if (!authApi) {
|
|
121
|
+
throw new Error("Auth not initialized. Call initAuth first.");
|
|
141
122
|
}
|
|
142
|
-
const currentUser = createRef({
|
|
143
|
-
id: "",
|
|
144
|
-
email: "",
|
|
145
|
-
first_name: "",
|
|
146
|
-
last_name: "",
|
|
147
|
-
is_superuser: false,
|
|
148
|
-
is_active: false
|
|
149
|
-
});
|
|
150
|
-
const passwordForm = createRef({
|
|
151
|
-
current_password: "",
|
|
152
|
-
new_password: "",
|
|
153
|
-
confirmNewPassword: ""
|
|
154
|
-
});
|
|
155
123
|
const getFullName = () => `${currentUser.value.first_name} ${currentUser.value.last_name}`;
|
|
156
124
|
const getIsLoggedIn = () => currentUser.value.id.length > 0;
|
|
157
|
-
function
|
|
158
|
-
if (onError) {
|
|
159
|
-
onError(error);
|
|
160
|
-
}
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
async function logout$1() {
|
|
125
|
+
async function logout() {
|
|
164
126
|
try {
|
|
165
|
-
await logout();
|
|
127
|
+
await authApi.logout();
|
|
166
128
|
} catch (error) {
|
|
167
|
-
|
|
129
|
+
throw error;
|
|
168
130
|
}
|
|
169
131
|
}
|
|
170
|
-
async function login
|
|
171
|
-
const email = credentials.email.toLowerCase();
|
|
172
|
-
const { password } = credentials;
|
|
132
|
+
async function login(credentials) {
|
|
173
133
|
try {
|
|
174
|
-
await login(email, password);
|
|
134
|
+
await authApi.login(credentials.email.toLowerCase(), credentials.password);
|
|
175
135
|
await checkAuth();
|
|
176
136
|
} catch (error) {
|
|
177
|
-
|
|
137
|
+
throw error;
|
|
178
138
|
}
|
|
179
139
|
}
|
|
180
140
|
async function checkAuth() {
|
|
181
141
|
try {
|
|
182
142
|
if (!getIsLoggedIn()) {
|
|
183
|
-
const { data } = await getCurrentUser();
|
|
143
|
+
const { data } = await authApi.getCurrentUser();
|
|
184
144
|
currentUser.set(data);
|
|
185
145
|
}
|
|
186
146
|
} catch (error) {
|
|
@@ -188,109 +148,83 @@ function useAuth() {
|
|
|
188
148
|
}
|
|
189
149
|
return getIsLoggedIn();
|
|
190
150
|
}
|
|
191
|
-
async function signup
|
|
151
|
+
async function signup(user) {
|
|
192
152
|
try {
|
|
193
153
|
if (user.password !== user.confirmPassword) {
|
|
194
154
|
throw new Error("Passwords do not match");
|
|
195
155
|
}
|
|
196
|
-
const { data } = await signup(user);
|
|
156
|
+
const { data } = await authApi.signup(user);
|
|
197
157
|
currentUser.set(data);
|
|
198
158
|
} catch (error) {
|
|
199
|
-
|
|
159
|
+
throw error;
|
|
200
160
|
}
|
|
201
161
|
}
|
|
202
162
|
async function recoverPassword(email) {
|
|
203
163
|
try {
|
|
204
|
-
await passwordRecovery(email);
|
|
164
|
+
await authApi.passwordRecovery(email);
|
|
205
165
|
} catch (error) {
|
|
206
|
-
|
|
166
|
+
throw error;
|
|
207
167
|
}
|
|
208
168
|
}
|
|
209
|
-
async function resetPassword
|
|
169
|
+
async function resetPassword(newPassword) {
|
|
210
170
|
try {
|
|
211
|
-
|
|
212
|
-
throw new Error("Passwords do not match");
|
|
213
|
-
}
|
|
214
|
-
await resetPassword(form.new_password);
|
|
215
|
-
form = {
|
|
216
|
-
current_password: "",
|
|
217
|
-
new_password: "",
|
|
218
|
-
confirmNewPassword: ""
|
|
219
|
-
};
|
|
171
|
+
await authApi.resetPassword(newPassword);
|
|
220
172
|
} catch (error) {
|
|
221
|
-
|
|
173
|
+
throw error;
|
|
222
174
|
}
|
|
223
175
|
}
|
|
224
|
-
async function updatePassword
|
|
176
|
+
async function updatePassword(form) {
|
|
225
177
|
try {
|
|
226
|
-
if (
|
|
178
|
+
if (form.new_password !== form.confirmNewPassword) {
|
|
227
179
|
throw new Error("Passwords do not match");
|
|
228
180
|
}
|
|
229
|
-
await updatePassword(
|
|
230
|
-
passwordForm.set({
|
|
231
|
-
current_password: "",
|
|
232
|
-
new_password: "",
|
|
233
|
-
confirmNewPassword: ""
|
|
234
|
-
});
|
|
181
|
+
await authApi.updatePassword(form);
|
|
235
182
|
} catch (error) {
|
|
236
|
-
|
|
183
|
+
throw error;
|
|
237
184
|
}
|
|
238
185
|
}
|
|
239
186
|
async function updateProfile(user) {
|
|
240
187
|
try {
|
|
241
|
-
const { data } = await updateUserProfile(user);
|
|
188
|
+
const { data } = await authApi.updateUserProfile(user);
|
|
242
189
|
currentUser.set({ ...currentUser.value, ...data });
|
|
243
190
|
} catch (error) {
|
|
244
|
-
|
|
191
|
+
throw error;
|
|
245
192
|
}
|
|
246
193
|
}
|
|
247
194
|
async function toggleUserStatus(userId, isActive) {
|
|
248
195
|
try {
|
|
249
|
-
await setUserStatus(userId, isActive);
|
|
196
|
+
await authApi.setUserStatus(userId, isActive);
|
|
250
197
|
} catch (error) {
|
|
251
|
-
|
|
198
|
+
throw error;
|
|
252
199
|
}
|
|
253
200
|
}
|
|
254
|
-
async function deleteUser
|
|
201
|
+
async function deleteUser(userId) {
|
|
255
202
|
try {
|
|
256
|
-
await deleteUser(userId);
|
|
203
|
+
await authApi.deleteUser(userId);
|
|
257
204
|
} catch (error) {
|
|
258
|
-
|
|
205
|
+
throw error;
|
|
259
206
|
}
|
|
260
207
|
}
|
|
261
208
|
return {
|
|
262
209
|
// State
|
|
263
210
|
currentUser,
|
|
264
|
-
passwordForm,
|
|
265
211
|
// Getters
|
|
266
212
|
getFullName,
|
|
267
213
|
getIsLoggedIn,
|
|
268
214
|
// Actions
|
|
269
|
-
logout
|
|
270
|
-
login
|
|
215
|
+
logout,
|
|
216
|
+
login,
|
|
271
217
|
checkAuth,
|
|
272
|
-
signup
|
|
218
|
+
signup,
|
|
273
219
|
recoverPassword,
|
|
274
|
-
resetPassword
|
|
275
|
-
updatePassword
|
|
220
|
+
resetPassword,
|
|
221
|
+
updatePassword,
|
|
276
222
|
updateProfile,
|
|
277
223
|
toggleUserStatus,
|
|
278
|
-
deleteUser
|
|
224
|
+
deleteUser
|
|
279
225
|
};
|
|
280
226
|
}
|
|
281
227
|
|
|
282
|
-
exports.
|
|
283
|
-
exports.deleteUser = deleteUser;
|
|
284
|
-
exports.getCurrentUser = getCurrentUser;
|
|
285
|
-
exports.getUser = getUser;
|
|
286
|
-
exports.getUsers = getUsers;
|
|
228
|
+
exports.AuthApi = AuthApi;
|
|
287
229
|
exports.initAuth = initAuth;
|
|
288
|
-
exports.login = login;
|
|
289
|
-
exports.logout = logout;
|
|
290
|
-
exports.passwordRecovery = passwordRecovery;
|
|
291
|
-
exports.resetPassword = resetPassword;
|
|
292
|
-
exports.setUserStatus = setUserStatus;
|
|
293
|
-
exports.signup = signup;
|
|
294
|
-
exports.updatePassword = updatePassword;
|
|
295
|
-
exports.updateUserProfile = updateUserProfile;
|
|
296
230
|
exports.useAuth = useAuth;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AxiosResponse
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { App } from 'vue';
|
|
2
3
|
|
|
3
4
|
interface User {
|
|
4
5
|
id: string;
|
|
@@ -86,38 +87,33 @@ type UpdateMeResponse = AxiosResponse<SanitizedUserOut>;
|
|
|
86
87
|
type UpdatePasswordResponse = AxiosResponse;
|
|
87
88
|
type SignupResponse = AxiosResponse<SanitizedUserOut>;
|
|
88
89
|
|
|
89
|
-
declare
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
declare class AuthApi {
|
|
91
|
+
private api;
|
|
92
|
+
constructor(baseURL?: string);
|
|
93
|
+
private setupInterceptors;
|
|
94
|
+
login(username: string, password: string): Promise<LoginResponse>;
|
|
95
|
+
logout(): void;
|
|
96
|
+
passwordRecovery(email?: string): Promise<PasswordRecoveryResponse>;
|
|
97
|
+
resetPassword(newPassword: NewPassword['new_password']): Promise<ResetPasswordResponse>;
|
|
98
|
+
getCurrentUser(): Promise<GetMeResponse>;
|
|
99
|
+
signup(user: NewUser): Promise<SignupResponse>;
|
|
100
|
+
updatePassword(form: UpdatePasswordForm): Promise<UpdatePasswordResponse>;
|
|
101
|
+
updateUserProfile(user: Partial<User>): Promise<UpdateMeResponse>;
|
|
102
|
+
setUserStatus(userId: string, isActive: boolean): Promise<UpdateUserResponse>;
|
|
103
|
+
deleteUser(userId: string): Promise<DeleteUserResponse>;
|
|
104
|
+
getUsers(limit?: number, skip?: number): Promise<GetUsersResponse>;
|
|
105
|
+
createUser(user: UserCreate): Promise<CreateUserResponse>;
|
|
106
|
+
getUser(userId: string): Promise<GetUserResponse>;
|
|
107
|
+
}
|
|
102
108
|
|
|
103
|
-
declare function initAuth(
|
|
104
|
-
|
|
105
|
-
errorHandler?: (error: any) => void;
|
|
106
|
-
reactive?: ReactiveFactory;
|
|
107
|
-
baseURL?: string;
|
|
108
|
-
}): {
|
|
109
|
-
install(app: any): void;
|
|
110
|
-
useAuth: typeof useAuth;
|
|
109
|
+
declare function initAuth(baseURL?: string): {
|
|
110
|
+
install(app: App): void;
|
|
111
111
|
};
|
|
112
112
|
declare function useAuth(): {
|
|
113
113
|
currentUser: {
|
|
114
114
|
value: User;
|
|
115
115
|
set: (newValue: User) => void;
|
|
116
116
|
};
|
|
117
|
-
passwordForm: {
|
|
118
|
-
value: UpdatePasswordForm;
|
|
119
|
-
set: (newValue: UpdatePasswordForm) => void;
|
|
120
|
-
};
|
|
121
117
|
getFullName: () => string;
|
|
122
118
|
getIsLoggedIn: () => boolean;
|
|
123
119
|
logout: () => Promise<void>;
|
|
@@ -128,11 +124,11 @@ declare function useAuth(): {
|
|
|
128
124
|
checkAuth: () => Promise<boolean>;
|
|
129
125
|
signup: (user: NewUser) => Promise<void>;
|
|
130
126
|
recoverPassword: (email: string) => Promise<void>;
|
|
131
|
-
resetPassword: (
|
|
132
|
-
updatePassword: () => Promise<void>;
|
|
127
|
+
resetPassword: (newPassword: string) => Promise<void>;
|
|
128
|
+
updatePassword: (form: UpdatePasswordForm) => Promise<void>;
|
|
133
129
|
updateProfile: (user: Partial<User>) => Promise<void>;
|
|
134
130
|
toggleUserStatus: (userId: string, isActive: boolean) => Promise<void>;
|
|
135
131
|
deleteUser: (userId: string) => Promise<void>;
|
|
136
132
|
};
|
|
137
133
|
|
|
138
|
-
export { type CreateUserResponse, type DeleteUserResponse, type GetMeResponse, type GetUserResponse, type GetUsersResponse, type LoginResponse, type NewPassword, type NewUser, type PasswordRecovery, type PasswordRecoveryResponse, type ReactiveFactory, type ResetPasswordResponse, type SanitizedUserList, type SanitizedUserOut, type SignupResponse, type Token, type UpdateMeResponse, type UpdatePassword, type UpdatePasswordForm, type UpdatePasswordResponse, type UpdateUserResponse, type User, type UserCreate, type UserRegister, type UserUpdate, type UserUpdateMe,
|
|
134
|
+
export { AuthApi, type CreateUserResponse, type DeleteUserResponse, type GetMeResponse, type GetUserResponse, type GetUsersResponse, type LoginResponse, type NewPassword, type NewUser, type PasswordRecovery, type PasswordRecoveryResponse, type ReactiveFactory, type ResetPasswordResponse, type SanitizedUserList, type SanitizedUserOut, type SignupResponse, type Token, type UpdateMeResponse, type UpdatePassword, type UpdatePasswordForm, type UpdatePasswordResponse, type UpdateUserResponse, type User, type UserCreate, type UserRegister, type UserUpdate, type UserUpdateMe, initAuth, useAuth };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AxiosResponse
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { App } from 'vue';
|
|
2
3
|
|
|
3
4
|
interface User {
|
|
4
5
|
id: string;
|
|
@@ -86,38 +87,33 @@ type UpdateMeResponse = AxiosResponse<SanitizedUserOut>;
|
|
|
86
87
|
type UpdatePasswordResponse = AxiosResponse;
|
|
87
88
|
type SignupResponse = AxiosResponse<SanitizedUserOut>;
|
|
88
89
|
|
|
89
|
-
declare
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
declare class AuthApi {
|
|
91
|
+
private api;
|
|
92
|
+
constructor(baseURL?: string);
|
|
93
|
+
private setupInterceptors;
|
|
94
|
+
login(username: string, password: string): Promise<LoginResponse>;
|
|
95
|
+
logout(): void;
|
|
96
|
+
passwordRecovery(email?: string): Promise<PasswordRecoveryResponse>;
|
|
97
|
+
resetPassword(newPassword: NewPassword['new_password']): Promise<ResetPasswordResponse>;
|
|
98
|
+
getCurrentUser(): Promise<GetMeResponse>;
|
|
99
|
+
signup(user: NewUser): Promise<SignupResponse>;
|
|
100
|
+
updatePassword(form: UpdatePasswordForm): Promise<UpdatePasswordResponse>;
|
|
101
|
+
updateUserProfile(user: Partial<User>): Promise<UpdateMeResponse>;
|
|
102
|
+
setUserStatus(userId: string, isActive: boolean): Promise<UpdateUserResponse>;
|
|
103
|
+
deleteUser(userId: string): Promise<DeleteUserResponse>;
|
|
104
|
+
getUsers(limit?: number, skip?: number): Promise<GetUsersResponse>;
|
|
105
|
+
createUser(user: UserCreate): Promise<CreateUserResponse>;
|
|
106
|
+
getUser(userId: string): Promise<GetUserResponse>;
|
|
107
|
+
}
|
|
102
108
|
|
|
103
|
-
declare function initAuth(
|
|
104
|
-
|
|
105
|
-
errorHandler?: (error: any) => void;
|
|
106
|
-
reactive?: ReactiveFactory;
|
|
107
|
-
baseURL?: string;
|
|
108
|
-
}): {
|
|
109
|
-
install(app: any): void;
|
|
110
|
-
useAuth: typeof useAuth;
|
|
109
|
+
declare function initAuth(baseURL?: string): {
|
|
110
|
+
install(app: App): void;
|
|
111
111
|
};
|
|
112
112
|
declare function useAuth(): {
|
|
113
113
|
currentUser: {
|
|
114
114
|
value: User;
|
|
115
115
|
set: (newValue: User) => void;
|
|
116
116
|
};
|
|
117
|
-
passwordForm: {
|
|
118
|
-
value: UpdatePasswordForm;
|
|
119
|
-
set: (newValue: UpdatePasswordForm) => void;
|
|
120
|
-
};
|
|
121
117
|
getFullName: () => string;
|
|
122
118
|
getIsLoggedIn: () => boolean;
|
|
123
119
|
logout: () => Promise<void>;
|
|
@@ -128,11 +124,11 @@ declare function useAuth(): {
|
|
|
128
124
|
checkAuth: () => Promise<boolean>;
|
|
129
125
|
signup: (user: NewUser) => Promise<void>;
|
|
130
126
|
recoverPassword: (email: string) => Promise<void>;
|
|
131
|
-
resetPassword: (
|
|
132
|
-
updatePassword: () => Promise<void>;
|
|
127
|
+
resetPassword: (newPassword: string) => Promise<void>;
|
|
128
|
+
updatePassword: (form: UpdatePasswordForm) => Promise<void>;
|
|
133
129
|
updateProfile: (user: Partial<User>) => Promise<void>;
|
|
134
130
|
toggleUserStatus: (userId: string, isActive: boolean) => Promise<void>;
|
|
135
131
|
deleteUser: (userId: string) => Promise<void>;
|
|
136
132
|
};
|
|
137
133
|
|
|
138
|
-
export { type CreateUserResponse, type DeleteUserResponse, type GetMeResponse, type GetUserResponse, type GetUsersResponse, type LoginResponse, type NewPassword, type NewUser, type PasswordRecovery, type PasswordRecoveryResponse, type ReactiveFactory, type ResetPasswordResponse, type SanitizedUserList, type SanitizedUserOut, type SignupResponse, type Token, type UpdateMeResponse, type UpdatePassword, type UpdatePasswordForm, type UpdatePasswordResponse, type UpdateUserResponse, type User, type UserCreate, type UserRegister, type UserUpdate, type UserUpdateMe,
|
|
134
|
+
export { AuthApi, type CreateUserResponse, type DeleteUserResponse, type GetMeResponse, type GetUserResponse, type GetUsersResponse, type LoginResponse, type NewPassword, type NewUser, type PasswordRecovery, type PasswordRecoveryResponse, type ReactiveFactory, type ResetPasswordResponse, type SanitizedUserList, type SanitizedUserOut, type SignupResponse, type Token, type UpdateMeResponse, type UpdatePassword, type UpdatePasswordForm, type UpdatePasswordResponse, type UpdateUserResponse, type User, type UserCreate, type UserRegister, type UserUpdate, type UserUpdateMe, initAuth, useAuth };
|