itube-specs 0.0.234 → 0.0.236

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.
@@ -6,141 +6,7 @@ import type {
6
6
  IPasswordForm,
7
7
  IRegistrateForm,
8
8
  IChangeEmail
9
- } from '../types';
10
- import { ApiHelper } from '../runtime';
11
-
12
- async function recoveryPasswordApi(data: IRecoveryPasswordForm): Promise<any> {
13
- return await ApiHelper.fetch('/authorization/recovery-password', {
14
- method: 'POST',
15
- headers: {
16
- 'X-Cache-Time': 259200,
17
- 'Content-Type': 'application/json',
18
- },
19
- body: data,
20
- });
21
- }
22
-
23
- async function changePasswordApi(data: IChangePasswordForm): Promise<any> {
24
- return await ApiHelper.fetch('/authorization/change-password', {
25
- method: 'POST',
26
- headers: {
27
- 'X-Cache-Time': 259200,
28
- 'Content-Type': 'application/json',
29
- },
30
- body: data,
31
- });
32
- }
33
-
34
- async function changeEmailApi(data: IChangeEmail): Promise<any> {
35
- console.log(data);
36
- return await ApiHelper.fetch('/authorization/change-email', {
37
- method: 'POST',
38
- headers: {
39
- 'X-Cache-Time': 259200,
40
- 'Content-Type': 'application/json',
41
- },
42
- body: data,
43
- });
44
- }
45
-
46
- async function postProfileApi(data: FormData): Promise<any> {
47
- return await ApiHelper.fetch('/authorization/post-profile', {
48
- method: 'POST',
49
- headers: {
50
- 'X-Cache-Time': 259200,
51
- },
52
- body: data,
53
- });
54
- }
55
-
56
- async function getProfileApi(): Promise<IProfileData | null> {
57
- return await ApiHelper.fetch('/authorization/get-profile', {
58
- method: 'GET',
59
- headers: {
60
- 'X-Cache-Time': 259200,
61
- 'Content-Type': 'application/json',
62
- },
63
- });
64
- }
65
-
66
- async function passwordApi(data: IPasswordForm): Promise<any> {
67
- return await ApiHelper.fetch('/authorization/password', {
68
- method: 'POST',
69
- headers: {
70
- 'X-Cache-Time': 259200,
71
- 'Content-Type': 'application/json',
72
- },
73
- body: data,
74
- });
75
- }
76
-
77
- async function deleteAvatarApi(): Promise<any> {
78
- return await ApiHelper.fetch('/authorization/profile-avatar', {
79
- method: 'DELETE',
80
- headers: {
81
- 'X-Cache-Time': 259200,
82
- 'Content-Type': 'application/json',
83
- },
84
- });
85
- }
86
-
87
- async function loginApi(data: ILoginForm): Promise<any> {
88
- return await ApiHelper.fetch('/authorization/login', {
89
- method: 'POST',
90
- headers: {
91
- 'X-Cache-Time': 259200,
92
- 'Content-Type': 'application/json',
93
- },
94
- body: data,
95
- });
96
- }
97
-
98
- async function registerApi(data: IRegistrateForm): Promise<any> {
99
- return await ApiHelper.fetch('/authorization/register', {
100
- method: 'POST',
101
- headers: {
102
- 'X-Cache-Time': 259200,
103
- 'Content-Type': 'application/json',
104
- },
105
- body: data,
106
- });
107
- }
108
-
109
- async function confirmRegistrationApi(token: string): Promise<any> {
110
- return await ApiHelper.fetch('/authorization/confirm', {
111
- method: 'GET',
112
- headers: {
113
- 'X-Cache-Time': 259200,
114
- 'X-Domain': useRuntimeConfig()?.public?.xDomain || useAppConfig().xDomain,
115
- 'Content-Type': 'application/json',
116
- },
117
- params: {
118
- token,
119
- }
120
- });
121
- }
122
-
123
- const { snackbarText, showErrorSnack } = useSnackbar();
124
-
125
- const register = async (form: IRegistrateForm) => {
126
- const response = await registerApi(form);
127
- if (response) {
128
- useCookie('jwtoken', { path: '/', secure: true, httpOnly: false }).value = response.token;
129
- await getProfile();
130
- }
131
- };
132
-
133
- const getProfile = async (update = false) => {
134
- const profileData = useState<IProfileData | null>('profileData', () => null);
135
-
136
- if (!profileData.value || update) {
137
- try {
138
- profileData.value = await getProfileApi();
139
- } catch (error) {
140
- console.error('Error get profile:', error);
141
- }
142
- }
143
- };
9
+ } from 'itube-specs/types';
144
10
 
145
11
  function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
146
12
  const result = {} as Omit<T, K>;
@@ -152,93 +18,116 @@ function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K
152
18
  return result;
153
19
  }
154
20
 
155
- const updateProfile = async (form: IProfileData) => {
156
- try {
157
- const formData = new FormData();
158
- const config = JSON.stringify(omit(form, ['avatar']));
159
-
160
- formData.append('config', config);
21
+ const { snackbarText, showErrorSnack } = useSnackbar();
161
22
 
162
- if (form.avatar) {
163
- formData.append('avatar', form.avatar);
23
+ export const useUser = (apiService) => {
24
+ const register = async (form: IRegistrateForm) => {
25
+ const response = await apiService.register(form);
26
+ if (response) {
27
+ useCookie('jwtoken', { path: '/', secure: true, httpOnly: false }).value = response.token;
28
+ await getProfile();
164
29
  }
30
+ };
165
31
 
166
- await postProfileApi(formData);
167
- } catch (error) {
168
- console.error('Error edit profile:', error);
169
- }
170
- };
32
+ const getProfile = async (update = false) => {
33
+ const profileData = useState<IProfileData | null>('profileData', () => null);
171
34
 
172
- const login = async (form: ILoginForm) => {
173
- const response = await loginApi(form);
174
- if (response) {
175
- useCookie('jwtoken', { path: '/', secure: true, httpOnly: false }).value = response.token;
176
- await getProfile();
177
- }
178
- };
35
+ if (!profileData.value || update) {
36
+ try {
37
+ profileData.value = await apiService.getProfile();
38
+ } catch (error) {
39
+ console.error('Error get profile:', error);
40
+ }
41
+ }
42
+ };
179
43
 
180
- const changePassword = async (form: IChangePasswordForm) => {
181
- try {
182
- await changePasswordApi(form);
183
- snackbarText.value = 'Password changed';
184
- } catch (err) {
185
- showErrorSnack('Error while changing password');
186
- console.log(err, 'error change password');
187
- }
188
- };
44
+ const updateProfile = async (form: IProfileData) => {
45
+ try {
46
+ const formData = new FormData();
47
+ const config = JSON.stringify(omit(form, ['avatar']));
189
48
 
190
- const changeEmail = async (form: IChangeEmail) => {
191
- try {
192
- await changeEmailApi(form);
193
- snackbarText.value = 'email_changed';
194
- } catch (err) {
195
- showErrorSnack('Error while changing email');
196
- console.log(err, 'error change email');
197
- }
198
- };
49
+ formData.append('config', config);
199
50
 
200
- const recoveryPassword = async (form: IRecoveryPasswordForm) => {
201
- try {
202
- await recoveryPasswordApi(form);
203
- snackbarText.value = 'Password recovered';
204
- await useRouter().push('/profile');
205
- } catch (err) {
206
- showErrorSnack('Error while recovery password');
207
- console.log(err, 'error change password');
208
- }
209
- };
51
+ if (form.avatar) {
52
+ formData.append('avatar', form.avatar);
53
+ }
210
54
 
211
- const password = async (form: IPasswordForm) => {
212
- await passwordApi(form);
213
- };
55
+ await apiService.postProfile(formData);
56
+ } catch (error) {
57
+ console.error('Error edit profile:', error);
58
+ }
59
+ };
214
60
 
215
- const deleteAvatar = async () => {
216
- await deleteAvatarApi();
217
- };
61
+ const login = async (form: ILoginForm) => {
62
+ const response = await apiService.login(form);
63
+ if (response) {
64
+ useCookie('jwtoken', { path: '/', secure: true, httpOnly: false }).value = response.token;
65
+ await getProfile();
66
+ }
67
+ };
218
68
 
219
- const signOut = () => {
220
- const cookie = useCookie('jwtoken', { path: '/', secure: true, httpOnly: false });
221
- cookie.value = undefined; // или null
222
- document.cookie = "jwtoken=; path=/; domain=gay.cool; expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure";;
69
+ const changePassword = async (form: IChangePasswordForm) => {
70
+ try {
71
+ await apiService.changePassword(form);
72
+ snackbarText.value = 'Password changed';
73
+ } catch (err) {
74
+ showErrorSnack('Error while changing password');
75
+ console.log(err, 'error change password');
76
+ }
77
+ };
223
78
 
224
- const profile = useState<IProfileData | null>('profileData');
225
- profile.value = null;
79
+ const changeEmail = async (form: IChangeEmail) => {
80
+ try {
81
+ await apiService.changeEmail(form);
82
+ snackbarText.value = 'email_changed';
83
+ } catch (err) {
84
+ showErrorSnack('Error while changing email');
85
+ console.log(err, 'error change email');
86
+ }
87
+ };
226
88
 
227
- const router = useRouter();
228
- router.push('/');
89
+ const recoveryPassword = async (form: IRecoveryPasswordForm) => {
90
+ try {
91
+ await apiService.recoveryPassword(form);
92
+ snackbarText.value = 'Password recovered';
93
+ await useRouter().push('/profile');
94
+ } catch (err) {
95
+ showErrorSnack('Error while recovery password');
96
+ console.log(err, 'error change password');
97
+ }
98
+ };
99
+
100
+ const password = async (form: IPasswordForm) => {
101
+ await apiService.password(form);
102
+ };
103
+
104
+ const deleteAvatar = async () => {
105
+ await apiService.deleteAvatar();
106
+ };
107
+
108
+ const signOut = () => {
109
+ const cookie = useCookie('jwtoken', { path: '/', secure: true, httpOnly: false });
110
+ cookie.value = undefined; // или null
111
+ document.cookie = "jwtoken=; path=/; domain=gay.cool; expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure";;
112
+
113
+ const profile = useState<IProfileData | null>('profileData');
114
+ profile.value = null;
115
+
116
+ const router = useRouter();
117
+ router.push('/');
118
+ };
119
+
120
+ return {
121
+ isAuthorized: computed(() => process.client && !!useCookie('jwtoken').value),
122
+ register,
123
+ login,
124
+ password,
125
+ signOut,
126
+ getProfile,
127
+ updateProfile,
128
+ changePassword,
129
+ recoveryPassword,
130
+ deleteAvatar,
131
+ changeEmail,
132
+ };
229
133
  };
230
-
231
- export const useUser = () => ({
232
- isAuthorized: computed(() => process.client && !!useCookie('jwtoken').value),
233
- register,
234
- login,
235
- password,
236
- signOut,
237
- getProfile,
238
- updateProfile,
239
- changePassword,
240
- recoveryPassword,
241
- deleteAvatar,
242
- changeEmail,
243
- confirmRegistrationApi,
244
- });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.234",
4
+ "version": "0.0.236",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
@@ -1,3 +0,0 @@
1
- export function useTestComposable() {
2
- console.log('useTestComposable')
3
- }