@goweekdays/layer-common 1.1.0 → 1.1.1
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/CHANGELOG.md +6 -0
- package/composables/useLocalAuth.ts +3 -33
- package/composables/useUtils.ts +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -44,38 +44,10 @@ export default function useLocalAuth() {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function setToken({
|
|
48
|
-
refreshToken = "",
|
|
49
|
-
accessToken = "",
|
|
50
|
-
user = "",
|
|
51
|
-
org = "",
|
|
52
|
-
}) {
|
|
53
|
-
useCookie("accessToken", cookieConfig).value = accessToken;
|
|
54
|
-
useCookie("refreshToken", cookieConfig).value = refreshToken;
|
|
55
|
-
useCookie("user", cookieConfig).value = user;
|
|
56
|
-
useCookie("org", cookieConfig).value = org;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function clearCookies() {
|
|
60
|
-
useCookie("accessToken", cookieConfig).value = null;
|
|
61
|
-
useCookie("refreshToken", cookieConfig).value = null;
|
|
62
|
-
useCookie("user", cookieConfig).value = null;
|
|
63
|
-
useCookie("organization", cookieConfig).value = null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
47
|
async function logout() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
await useNuxtApp().$api(`/api/auth/logout/${refreshToken}`, {
|
|
71
|
-
method: "DELETE",
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
clearCookies();
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error("Logout failed:", error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
48
|
+
useCookie("sid", cookieConfig).value = null;
|
|
49
|
+
useCookie("user", cookieConfig).value = null;
|
|
50
|
+
useCookie("role", cookieConfig).value = null;
|
|
79
51
|
}
|
|
80
52
|
|
|
81
53
|
async function getCurrentUser() {
|
|
@@ -145,9 +117,7 @@ export default function useLocalAuth() {
|
|
|
145
117
|
authenticate,
|
|
146
118
|
login,
|
|
147
119
|
logout,
|
|
148
|
-
clearCookies,
|
|
149
120
|
getCurrentUser,
|
|
150
|
-
setToken,
|
|
151
121
|
forgotPassword,
|
|
152
122
|
resetPassword,
|
|
153
123
|
currentUser,
|
package/composables/useUtils.ts
CHANGED
|
@@ -3,7 +3,7 @@ export default function useUtils() {
|
|
|
3
3
|
|
|
4
4
|
const emailRule = (v: string): true | string => {
|
|
5
5
|
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
6
|
-
if(!v) return true;
|
|
6
|
+
if (!v) return true;
|
|
7
7
|
return regex.test(v) || "Please enter a valid email address";
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -266,6 +266,10 @@ export default function useUtils() {
|
|
|
266
266
|
return params;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
function positiveNumberRule(v: number) {
|
|
270
|
+
return (v && v >= 1) || "Value must be greater or equal to 1";
|
|
271
|
+
}
|
|
272
|
+
|
|
269
273
|
return {
|
|
270
274
|
requiredRule,
|
|
271
275
|
emailRule,
|
|
@@ -291,5 +295,6 @@ export default function useUtils() {
|
|
|
291
295
|
getRouteParam,
|
|
292
296
|
replaceMatch,
|
|
293
297
|
setRouteParams,
|
|
298
|
+
positiveNumberRule,
|
|
294
299
|
};
|
|
295
300
|
}
|