@eeplatform/nuxt-layer-common 1.2.2 → 1.2.4
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 +12 -0
- package/components/InvitationForm.vue +206 -0
- package/components/InvitationMain.vue +46 -14
- package/components/MemberMain.vue +1 -6
- package/components/RolePermissionMain.vue +0 -1
- package/components/SchoolFormCreate.vue +216 -0
- package/components/SchoolFormEdit.vue +177 -0
- package/components/SchoolMain.vue +429 -0
- package/composables/useLocalAuth.ts +9 -20
- package/composables/useLocalSetup.ts +2 -36
- package/composables/useSchool.ts +3 -3
- package/middleware/01.auth.ts +2 -3
- package/nuxt.config.ts +1 -0
- package/package.json +1 -1
- package/plugins/API.ts +2 -39
- package/plugins/secure-member.client.ts +51 -0
package/composables/useSchool.ts
CHANGED
|
@@ -28,12 +28,12 @@ export default function useSchool() {
|
|
|
28
28
|
page = 1,
|
|
29
29
|
status = "active",
|
|
30
30
|
search = "",
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
org = "",
|
|
32
|
+
app = "admin",
|
|
33
33
|
} = {}) {
|
|
34
34
|
return useNuxtApp().$api<Record<string, any>>("/api/schools", {
|
|
35
35
|
method: "GET",
|
|
36
|
-
query: { page, status, search,
|
|
36
|
+
query: { page, status, search, org, app },
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
package/middleware/01.auth.ts
CHANGED
|
@@ -4,10 +4,9 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
4
4
|
|
|
5
5
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const accessToken = useCookie("accessToken", cookieConfig).value;
|
|
7
|
+
const sid = useCookie("sid", cookieConfig).value;
|
|
9
8
|
|
|
10
|
-
if (!
|
|
9
|
+
if (!sid) {
|
|
11
10
|
// Redirect to login page if no access token
|
|
12
11
|
return navigateTo({ name: "index" });
|
|
13
12
|
}
|
package/nuxt.config.ts
CHANGED
|
@@ -15,6 +15,7 @@ export default defineNuxtConfig({
|
|
|
15
15
|
secure: true,
|
|
16
16
|
maxAge: 30 * 24 * 60 * 60,
|
|
17
17
|
},
|
|
18
|
+
APP: (process.env.APP as string) ?? "App",
|
|
18
19
|
APP_NAME: (process.env.APP_NAME as string) ?? "App",
|
|
19
20
|
APP_NAME_ROUTE: (process.env.APP_NAME_ROUTE as string) ?? "index",
|
|
20
21
|
S3_BUCKET_ENDPOINT: (process.env.S3_BUCKET_ENDPOINT as string) ?? "",
|
package/package.json
CHANGED
package/plugins/API.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { useFetch } from "nuxt/app";
|
|
2
|
-
type useFetchType = typeof useFetch;
|
|
3
|
-
|
|
4
1
|
export default defineNuxtPlugin(() => {
|
|
5
2
|
const { cookieConfig, BASE_URL } = useRuntimeConfig().public;
|
|
6
3
|
|
|
@@ -10,49 +7,15 @@ export default defineNuxtPlugin(() => {
|
|
|
10
7
|
retryStatusCodes: [401],
|
|
11
8
|
retryDelay: 500,
|
|
12
9
|
onRequest({ options }) {
|
|
13
|
-
const
|
|
14
|
-
options.headers.set("
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
async onResponseError({ response }) {
|
|
18
|
-
if (response.status === 401) {
|
|
19
|
-
await $fetch("/api/auth/refresh", {
|
|
20
|
-
method: "POST",
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
token: useCookie("refreshToken", cookieConfig).value,
|
|
23
|
-
}),
|
|
24
|
-
|
|
25
|
-
onResponse({ response }) {
|
|
26
|
-
if (response.status === 200) {
|
|
27
|
-
useCookie("accessToken", cookieConfig).value =
|
|
28
|
-
response._data.token;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
10
|
+
const sid = useCookie("sid", cookieConfig).value ?? "";
|
|
11
|
+
options.headers.set("authorization", sid);
|
|
33
12
|
},
|
|
34
13
|
});
|
|
35
14
|
|
|
36
|
-
const useAPI: useFetchType = (path, options = {}) => {
|
|
37
|
-
options.lazy = true;
|
|
38
|
-
options.retry = 1;
|
|
39
|
-
options.retryStatusCodes = [401];
|
|
40
|
-
options.retryDelay = 500;
|
|
41
|
-
options.baseURL = (BASE_URL as string) ?? "/";
|
|
42
|
-
|
|
43
|
-
options.headers = {
|
|
44
|
-
...options.headers,
|
|
45
|
-
Authorization: `Bearer ${useCookie("accessToken", cookieConfig).value}`,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return useFetch(path, options);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
15
|
// Expose to useNuxtApp().$api
|
|
52
16
|
return {
|
|
53
17
|
provide: {
|
|
54
18
|
api,
|
|
55
|
-
useAPI,
|
|
56
19
|
},
|
|
57
20
|
};
|
|
58
21
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export default defineNuxtPlugin(() => {
|
|
2
|
+
const router = useRouter();
|
|
3
|
+
const { getByUserType } = useMember();
|
|
4
|
+
const { getRoleById } = useRole();
|
|
5
|
+
|
|
6
|
+
const { userAppRole, id } = useLocalSetup();
|
|
7
|
+
|
|
8
|
+
router.afterEach((to) => {
|
|
9
|
+
const isSecured = to.meta?.secured;
|
|
10
|
+
if (!isSecured) return;
|
|
11
|
+
|
|
12
|
+
const APP = useRuntimeConfig().public.APP;
|
|
13
|
+
const org = (to.params.org as string) ?? "";
|
|
14
|
+
|
|
15
|
+
const userId = computed(() => useCookie("user").value ?? "");
|
|
16
|
+
|
|
17
|
+
const { data: userMemberData, error: userMemberError } = useLazyAsyncData(
|
|
18
|
+
"get-member-by-id",
|
|
19
|
+
() => getByUserType(userId.value, APP, org),
|
|
20
|
+
{ watch: [userId] }
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
watchEffect(() => {
|
|
24
|
+
if (userMemberError.value) {
|
|
25
|
+
navigateTo({
|
|
26
|
+
name: "index",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
watchEffect(() => {
|
|
32
|
+
if (userMemberData.value) {
|
|
33
|
+
id.value = userMemberData.value.org ?? "";
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const roleId = computed(() => userMemberData.value?.role ?? "");
|
|
38
|
+
|
|
39
|
+
const { data: getRoleByIdReq } = useLazyAsyncData(
|
|
40
|
+
"get-role-by-id",
|
|
41
|
+
() => getRoleById(roleId.value),
|
|
42
|
+
{ watch: [roleId], immediate: false }
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
watchEffect(() => {
|
|
46
|
+
if (getRoleByIdReq.value) {
|
|
47
|
+
userAppRole.value = getRoleByIdReq.value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|