@bagelink/auth 1.1.43 → 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 +27 -12
- package/dist/index.d.cts +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.mjs +27 -12
- package/package.json +1 -1
- package/src/api/auth.ts +27 -18
- package/src/composable/useAuth.ts +15 -5
- package/src/utils.ts +12 -0
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,16 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
8
8
|
|
|
9
|
+
function createAxiosInstance(baseURL = "") {
|
|
10
|
+
return axios__default.create({
|
|
11
|
+
baseURL: baseURL || "",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
"withCredentials": true
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
var __defProp = Object.defineProperty;
|
|
10
20
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
21
|
var __publicField = (obj, key, value) => {
|
|
@@ -13,14 +23,9 @@ var __publicField = (obj, key, value) => {
|
|
|
13
23
|
return value;
|
|
14
24
|
};
|
|
15
25
|
class AuthApi {
|
|
16
|
-
constructor(baseURL) {
|
|
26
|
+
constructor(axiosInstance, baseURL = "") {
|
|
17
27
|
__publicField(this, "api");
|
|
18
|
-
this.api =
|
|
19
|
-
baseURL,
|
|
20
|
-
headers: {
|
|
21
|
-
"Content-Type": "application/json"
|
|
22
|
-
}
|
|
23
|
-
});
|
|
28
|
+
this.api = axiosInstance || createAxiosInstance(baseURL);
|
|
24
29
|
this.setupInterceptors();
|
|
25
30
|
}
|
|
26
31
|
setupInterceptors() {
|
|
@@ -76,13 +81,17 @@ class AuthApi {
|
|
|
76
81
|
return this.api.patch("/users/me", user);
|
|
77
82
|
}
|
|
78
83
|
async setUserStatus(userId, isActive) {
|
|
79
|
-
return this.api.patch(`/users/${userId}`, {
|
|
84
|
+
return this.api.patch(`/users/${userId}`, {
|
|
85
|
+
is_active: isActive
|
|
86
|
+
});
|
|
80
87
|
}
|
|
81
88
|
async deleteUser(userId) {
|
|
82
89
|
return this.api.delete(`/users/${userId}`);
|
|
83
90
|
}
|
|
84
91
|
async getUsers(limit = 100, skip) {
|
|
85
|
-
return this.api.get("/users/", {
|
|
92
|
+
return this.api.get("/users/", {
|
|
93
|
+
params: { skip, limit }
|
|
94
|
+
});
|
|
86
95
|
}
|
|
87
96
|
async createUser(user) {
|
|
88
97
|
return this.api.post("/users/", user);
|
|
@@ -106,9 +115,12 @@ const currentUser = {
|
|
|
106
115
|
currentUser.value = newValue;
|
|
107
116
|
}
|
|
108
117
|
};
|
|
109
|
-
function initAuth(
|
|
118
|
+
function initAuth({
|
|
119
|
+
axios,
|
|
120
|
+
baseURL
|
|
121
|
+
}) {
|
|
110
122
|
if (!authApi) {
|
|
111
|
-
authApi = new AuthApi(baseURL);
|
|
123
|
+
authApi = new AuthApi(axios, baseURL);
|
|
112
124
|
}
|
|
113
125
|
return {
|
|
114
126
|
install(app) {
|
|
@@ -131,7 +143,10 @@ function useAuth() {
|
|
|
131
143
|
}
|
|
132
144
|
async function login(credentials) {
|
|
133
145
|
try {
|
|
134
|
-
await authApi.login(
|
|
146
|
+
await authApi.login(
|
|
147
|
+
credentials.email.toLowerCase(),
|
|
148
|
+
credentials.password
|
|
149
|
+
);
|
|
135
150
|
await checkAuth();
|
|
136
151
|
} catch (error) {
|
|
137
152
|
throw error;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
1
|
+
import { AxiosResponse, AxiosInstance } from 'axios';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
|
|
4
4
|
interface User {
|
|
@@ -89,7 +89,7 @@ type SignupResponse = AxiosResponse<SanitizedUserOut>;
|
|
|
89
89
|
|
|
90
90
|
declare class AuthApi {
|
|
91
91
|
private api;
|
|
92
|
-
constructor(baseURL?: string);
|
|
92
|
+
constructor(axiosInstance?: AxiosInstance, baseURL?: string);
|
|
93
93
|
private setupInterceptors;
|
|
94
94
|
login(username: string, password: string): Promise<LoginResponse>;
|
|
95
95
|
logout(): void;
|
|
@@ -106,7 +106,10 @@ declare class AuthApi {
|
|
|
106
106
|
getUser(userId: string): Promise<GetUserResponse>;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
declare function initAuth(baseURL
|
|
109
|
+
declare function initAuth({ axios, baseURL, }: {
|
|
110
|
+
axios: AxiosInstance;
|
|
111
|
+
baseURL?: string;
|
|
112
|
+
}): {
|
|
110
113
|
install(app: App): void;
|
|
111
114
|
};
|
|
112
115
|
declare function useAuth(): {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
1
|
+
import { AxiosResponse, AxiosInstance } from 'axios';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
|
|
4
4
|
interface User {
|
|
@@ -89,7 +89,7 @@ type SignupResponse = AxiosResponse<SanitizedUserOut>;
|
|
|
89
89
|
|
|
90
90
|
declare class AuthApi {
|
|
91
91
|
private api;
|
|
92
|
-
constructor(baseURL?: string);
|
|
92
|
+
constructor(axiosInstance?: AxiosInstance, baseURL?: string);
|
|
93
93
|
private setupInterceptors;
|
|
94
94
|
login(username: string, password: string): Promise<LoginResponse>;
|
|
95
95
|
logout(): void;
|
|
@@ -106,7 +106,10 @@ declare class AuthApi {
|
|
|
106
106
|
getUser(userId: string): Promise<GetUserResponse>;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
declare function initAuth(baseURL
|
|
109
|
+
declare function initAuth({ axios, baseURL, }: {
|
|
110
|
+
axios: AxiosInstance;
|
|
111
|
+
baseURL?: string;
|
|
112
|
+
}): {
|
|
110
113
|
install(app: App): void;
|
|
111
114
|
};
|
|
112
115
|
declare function useAuth(): {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
1
|
+
import { AxiosResponse, AxiosInstance } from 'axios';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
|
|
4
4
|
interface User {
|
|
@@ -89,7 +89,7 @@ type SignupResponse = AxiosResponse<SanitizedUserOut>;
|
|
|
89
89
|
|
|
90
90
|
declare class AuthApi {
|
|
91
91
|
private api;
|
|
92
|
-
constructor(baseURL?: string);
|
|
92
|
+
constructor(axiosInstance?: AxiosInstance, baseURL?: string);
|
|
93
93
|
private setupInterceptors;
|
|
94
94
|
login(username: string, password: string): Promise<LoginResponse>;
|
|
95
95
|
logout(): void;
|
|
@@ -106,7 +106,10 @@ declare class AuthApi {
|
|
|
106
106
|
getUser(userId: string): Promise<GetUserResponse>;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
declare function initAuth(baseURL
|
|
109
|
+
declare function initAuth({ axios, baseURL, }: {
|
|
110
|
+
axios: AxiosInstance;
|
|
111
|
+
baseURL?: string;
|
|
112
|
+
}): {
|
|
110
113
|
install(app: App): void;
|
|
111
114
|
};
|
|
112
115
|
declare function useAuth(): {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
+
function createAxiosInstance(baseURL = "") {
|
|
4
|
+
return axios.create({
|
|
5
|
+
baseURL: baseURL || "",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
"withCredentials": true
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
var __defProp = Object.defineProperty;
|
|
4
14
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
15
|
var __publicField = (obj, key, value) => {
|
|
@@ -7,14 +17,9 @@ var __publicField = (obj, key, value) => {
|
|
|
7
17
|
return value;
|
|
8
18
|
};
|
|
9
19
|
class AuthApi {
|
|
10
|
-
constructor(baseURL) {
|
|
20
|
+
constructor(axiosInstance, baseURL = "") {
|
|
11
21
|
__publicField(this, "api");
|
|
12
|
-
this.api =
|
|
13
|
-
baseURL,
|
|
14
|
-
headers: {
|
|
15
|
-
"Content-Type": "application/json"
|
|
16
|
-
}
|
|
17
|
-
});
|
|
22
|
+
this.api = axiosInstance || createAxiosInstance(baseURL);
|
|
18
23
|
this.setupInterceptors();
|
|
19
24
|
}
|
|
20
25
|
setupInterceptors() {
|
|
@@ -70,13 +75,17 @@ class AuthApi {
|
|
|
70
75
|
return this.api.patch("/users/me", user);
|
|
71
76
|
}
|
|
72
77
|
async setUserStatus(userId, isActive) {
|
|
73
|
-
return this.api.patch(`/users/${userId}`, {
|
|
78
|
+
return this.api.patch(`/users/${userId}`, {
|
|
79
|
+
is_active: isActive
|
|
80
|
+
});
|
|
74
81
|
}
|
|
75
82
|
async deleteUser(userId) {
|
|
76
83
|
return this.api.delete(`/users/${userId}`);
|
|
77
84
|
}
|
|
78
85
|
async getUsers(limit = 100, skip) {
|
|
79
|
-
return this.api.get("/users/", {
|
|
86
|
+
return this.api.get("/users/", {
|
|
87
|
+
params: { skip, limit }
|
|
88
|
+
});
|
|
80
89
|
}
|
|
81
90
|
async createUser(user) {
|
|
82
91
|
return this.api.post("/users/", user);
|
|
@@ -100,9 +109,12 @@ const currentUser = {
|
|
|
100
109
|
currentUser.value = newValue;
|
|
101
110
|
}
|
|
102
111
|
};
|
|
103
|
-
function initAuth(
|
|
112
|
+
function initAuth({
|
|
113
|
+
axios,
|
|
114
|
+
baseURL
|
|
115
|
+
}) {
|
|
104
116
|
if (!authApi) {
|
|
105
|
-
authApi = new AuthApi(baseURL);
|
|
117
|
+
authApi = new AuthApi(axios, baseURL);
|
|
106
118
|
}
|
|
107
119
|
return {
|
|
108
120
|
install(app) {
|
|
@@ -125,7 +137,10 @@ function useAuth() {
|
|
|
125
137
|
}
|
|
126
138
|
async function login(credentials) {
|
|
127
139
|
try {
|
|
128
|
-
await authApi.login(
|
|
140
|
+
await authApi.login(
|
|
141
|
+
credentials.email.toLowerCase(),
|
|
142
|
+
credentials.password
|
|
143
|
+
);
|
|
129
144
|
await checkAuth();
|
|
130
145
|
} catch (error) {
|
|
131
146
|
throw error;
|
package/package.json
CHANGED
package/src/api/auth.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InternalAxiosRequestConfig } from 'axios'
|
|
1
|
+
import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios'
|
|
2
2
|
import type {
|
|
3
3
|
User,
|
|
4
4
|
NewUser,
|
|
@@ -19,20 +19,15 @@ import type {
|
|
|
19
19
|
GetMeResponse,
|
|
20
20
|
UpdateMeResponse,
|
|
21
21
|
UpdatePasswordResponse,
|
|
22
|
-
SignupResponse
|
|
22
|
+
SignupResponse,
|
|
23
23
|
} from '../types'
|
|
24
|
-
import
|
|
24
|
+
import { createAxiosInstance } from '../utils'
|
|
25
25
|
|
|
26
26
|
export class AuthApi {
|
|
27
|
-
private api:
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
this.api =
|
|
31
|
-
baseURL,
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
},
|
|
35
|
-
})
|
|
27
|
+
private api: AxiosInstance
|
|
28
|
+
|
|
29
|
+
constructor(axiosInstance?: AxiosInstance, baseURL: string = '') {
|
|
30
|
+
this.api = axiosInstance || createAxiosInstance(baseURL)
|
|
36
31
|
this.setupInterceptors()
|
|
37
32
|
}
|
|
38
33
|
|
|
@@ -71,7 +66,9 @@ export class AuthApi {
|
|
|
71
66
|
return this.api.post('/auth/password-recovery', { email })
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
async resetPassword(
|
|
69
|
+
async resetPassword(
|
|
70
|
+
newPassword: NewPassword['new_password']
|
|
71
|
+
): Promise<ResetPasswordResponse> {
|
|
75
72
|
return this.api.post('/auth/reset-password', { new_password: newPassword })
|
|
76
73
|
}
|
|
77
74
|
|
|
@@ -88,7 +85,9 @@ export class AuthApi {
|
|
|
88
85
|
})
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
async updatePassword(
|
|
88
|
+
async updatePassword(
|
|
89
|
+
form: UpdatePasswordForm
|
|
90
|
+
): Promise<UpdatePasswordResponse> {
|
|
92
91
|
return this.api.patch('/users/me/password', {
|
|
93
92
|
current_password: form.current_password,
|
|
94
93
|
new_password: form.new_password,
|
|
@@ -99,16 +98,26 @@ export class AuthApi {
|
|
|
99
98
|
return this.api.patch<SanitizedUserOut>('/users/me', user)
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
async setUserStatus(
|
|
103
|
-
|
|
101
|
+
async setUserStatus(
|
|
102
|
+
userId: string,
|
|
103
|
+
isActive: boolean
|
|
104
|
+
): Promise<UpdateUserResponse> {
|
|
105
|
+
return this.api.patch<SanitizedUserOut>(`/users/${userId}`, {
|
|
106
|
+
is_active: isActive,
|
|
107
|
+
})
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
async deleteUser(userId: string): Promise<DeleteUserResponse> {
|
|
107
111
|
return this.api.delete(`/users/${userId}`)
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
async getUsers(
|
|
111
|
-
|
|
114
|
+
async getUsers(
|
|
115
|
+
limit: number = 100,
|
|
116
|
+
skip?: number
|
|
117
|
+
): Promise<GetUsersResponse> {
|
|
118
|
+
return this.api.get<SanitizedUserList>('/users/', {
|
|
119
|
+
params: { skip, limit },
|
|
120
|
+
})
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
async createUser(user: UserCreate): Promise<CreateUserResponse> {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios'
|
|
1
2
|
import type { App } from 'vue'
|
|
2
3
|
import type { User, NewUser, UpdatePasswordForm } from '../types'
|
|
3
4
|
import { AuthApi } from '../api/auth'
|
|
@@ -15,20 +16,26 @@ const currentUser = {
|
|
|
15
16
|
} as User,
|
|
16
17
|
set: (newValue: User) => {
|
|
17
18
|
currentUser.value = newValue
|
|
18
|
-
}
|
|
19
|
+
},
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
// Initialize auth
|
|
22
|
-
export function initAuth(
|
|
23
|
+
export function initAuth({
|
|
24
|
+
axios,
|
|
25
|
+
baseURL,
|
|
26
|
+
}: {
|
|
27
|
+
axios: AxiosInstance
|
|
28
|
+
baseURL?: string
|
|
29
|
+
}) {
|
|
23
30
|
if (!authApi) {
|
|
24
|
-
authApi = new AuthApi(baseURL)
|
|
31
|
+
authApi = new AuthApi(axios, baseURL)
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
return {
|
|
28
35
|
install(app: App) {
|
|
29
36
|
// Make auth available globally
|
|
30
37
|
app.config.globalProperties.$auth = useAuth()
|
|
31
|
-
}
|
|
38
|
+
},
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
|
|
@@ -53,7 +60,10 @@ export function useAuth() {
|
|
|
53
60
|
|
|
54
61
|
async function login(credentials: { email: string, password: string }) {
|
|
55
62
|
try {
|
|
56
|
-
await authApi!.login(
|
|
63
|
+
await authApi!.login(
|
|
64
|
+
credentials.email.toLowerCase(),
|
|
65
|
+
credentials.password
|
|
66
|
+
)
|
|
57
67
|
await checkAuth()
|
|
58
68
|
} catch (error) {
|
|
59
69
|
throw error
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios'
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
|
|
4
|
+
export function createAxiosInstance(baseURL: string = ''): AxiosInstance {
|
|
5
|
+
return axios.create({
|
|
6
|
+
baseURL: baseURL || '',
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
'withCredentials': true,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
}
|