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