@goweekdays/layer-common 1.3.0 → 1.3.2

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.
@@ -12,32 +12,6 @@ export default function useLocalAuth() {
12
12
  });
13
13
  };
14
14
 
15
- function authenticate() {
16
- if (currentUser.value) {
17
- return;
18
- }
19
-
20
- const user = useCookie("user", cookieConfig).value;
21
-
22
- const { data: getCurrentUserReq, error: getCurrentUserErr } =
23
- useLazyAsyncData("get-current-user", () =>
24
- $fetch<TUser>(`/api/users/id/${user}`)
25
- );
26
-
27
- watchEffect(() => {
28
- if (getCurrentUserReq.value) {
29
- currentUser.value = getCurrentUserReq.value;
30
- }
31
- });
32
-
33
- watchEffect(() => {
34
- if (getCurrentUserErr.value) {
35
- // Redirect to login page if user authentication fails
36
- navigateTo({ name: "index" });
37
- }
38
- });
39
- }
40
-
41
15
  async function login({ email = "", password = "", role = "" }) {
42
16
  return $fetch<Record<string, any>>("/api/auth/login", {
43
17
  method: "POST",
@@ -107,11 +81,8 @@ export default function useLocalAuth() {
107
81
  });
108
82
  }
109
83
 
110
- function signUp(email: string, referral: string) {
111
- return $fetch<TKeyValuePair>("/api/auth/sign-up", {
112
- method: "POST",
113
- body: { email, referral },
114
- });
84
+ function loggedInUser() {
85
+ return useCookie("user", cookieConfig).value ?? "";
115
86
  }
116
87
 
117
88
  return {
@@ -119,13 +90,12 @@ export default function useLocalAuth() {
119
90
  membership,
120
91
  permissions,
121
92
  hasPermission,
122
- authenticate,
123
93
  login,
124
94
  logout,
125
95
  getCurrentUser,
126
96
  forgotPassword,
127
97
  resetPassword,
128
98
  verify,
129
- signUp,
99
+ loggedInUser,
130
100
  };
131
101
  }
@@ -1,25 +1,19 @@
1
1
  export default function useMember() {
2
- const members = useState<Array<TMember>>("members", () => []);
3
- const page = useState("page", () => 1);
4
- const pages = useState("pages", () => 0);
5
- const pageRange = useState("pageRange", () => "-- - -- of --");
6
-
7
- const member = useState<TMember>("member", () => ({
8
- _id: "",
2
+ const member = ref<TMember>({
9
3
  org: "",
10
4
  orgName: "",
11
- roleName: "",
12
5
  name: "",
13
6
  user: "",
14
7
  role: "",
15
- type: "",
16
- customerOrgId: "",
17
- customerSiteId: "",
18
- status: "",
19
- createdAt: "",
20
- updatedAt: "",
21
- deletedAt: "",
22
- }));
8
+ });
9
+
10
+ const invitation = ref<TMemberInvitation>({
11
+ _id: "",
12
+ email: "",
13
+ app: "",
14
+ org: "",
15
+ role: "",
16
+ });
23
17
 
24
18
  function getByUserId(user: string) {
25
19
  return $fetch<TMember>(`/api/members/user/${user}`);
@@ -32,18 +26,25 @@ export default function useMember() {
32
26
  });
33
27
  }
34
28
 
29
+ function getByApp({ app = "", user = "", org = "" } = {}) {
30
+ return $fetch<TMember>(`/api/members/app/${app}/user/${user}`, {
31
+ method: "GET",
32
+ query: { org },
33
+ });
34
+ }
35
+
35
36
  async function getAll({
36
37
  page = 1,
37
38
  search = "",
38
39
  limit = 10,
39
40
  user = "",
40
41
  org = "",
41
- type = "",
42
+ app = "",
42
43
  status = "active",
43
44
  } = {}) {
44
- return $fetch<Record<string, any>>("/api/members", {
45
+ return $fetch<Record<string, any>>(`/api/members/app/${app}`, {
45
46
  method: "GET",
46
- query: { page, limit, search, user, org, type, status },
47
+ query: { page, limit, search, user, org, status },
47
48
  });
48
49
  }
49
50
  function createUserByVerification(
@@ -70,32 +71,38 @@ export default function useMember() {
70
71
  );
71
72
  }
72
73
 
73
- function updateMemberRole(
74
- id: string,
75
- role: string,
76
- type: string,
77
- org: string
78
- ) {
79
- return $fetch<Record<string, any>>(
80
- `/api/members/id/${id}/role/${role}/type/${type}/org/${org}`,
81
- {
82
- method: "PUT",
83
- }
84
- );
74
+ function updateRoleById(id: string, role: string) {
75
+ return $fetch<Record<string, any>>(`/api/members/role/id/${id}`, {
76
+ method: "PATCH",
77
+ body: { role },
78
+ });
85
79
  }
80
+
81
+ function updateStatusById(id: string, status: string) {
82
+ return $fetch<Record<string, any>>(`/api/members/status/id/${id}`, {
83
+ method: "PATCH",
84
+ body: { status },
85
+ });
86
+ }
87
+
88
+ function deleteById(id: string) {
89
+ return $fetch<Record<string, any>>(`/api/members/id/${id}`, {
90
+ method: "DELETE",
91
+ });
92
+ }
93
+
86
94
  return {
87
- members,
88
95
  member,
89
- page,
90
- pages,
91
- pageRange,
92
-
96
+ invitation,
93
97
  getAll,
94
98
  getByUserId,
95
99
  createUserByVerification,
96
100
  createMemberInvite,
97
101
  getByUserType,
102
+ getByApp,
98
103
  updateMemberStatus,
99
- updateMemberRole,
104
+ updateRoleById,
105
+ updateStatusById,
106
+ deleteById,
100
107
  };
101
108
  }
@@ -1,5 +1,7 @@
1
1
  export default function useRole() {
2
- function add(value: Pick<TRole, "name" | "permissions" | "type" | "org">) {
2
+ function add(
3
+ value: Pick<TRole, "name" | "permissions" | "app" | "org" | "createdBy">
4
+ ) {
3
5
  return $fetch("/api/roles", {
4
6
  method: "POST",
5
7
  body: value,
@@ -10,12 +12,12 @@ export default function useRole() {
10
12
  search = "",
11
13
  page = 1,
12
14
  limit = 20,
13
- type = "",
15
+ app = "",
14
16
  org = "",
15
17
  } = {}) {
16
18
  return $fetch<Record<string, any>>("/api/roles", {
17
19
  method: "GET",
18
- query: { search, page, limit, type, org },
20
+ query: { search, page, limit, app, org },
19
21
  });
20
22
  }
21
23
 
@@ -56,7 +58,7 @@ export default function useRole() {
56
58
  name: "",
57
59
  org: "",
58
60
  permissions: [],
59
- type: "",
61
+ app: "",
60
62
  description: "",
61
63
  });
62
64
 
@@ -13,7 +13,35 @@ export default function useUser() {
13
13
  });
14
14
  }
15
15
 
16
+ function inviteMember(value: {
17
+ email: string;
18
+ app: string;
19
+ org: string;
20
+ role: string;
21
+ }) {
22
+ return $fetch<Record<string, any>>("/api/verifications/member", {
23
+ method: "POST",
24
+ body: value,
25
+ });
26
+ }
27
+
28
+ function signUp(email: string) {
29
+ return $fetch<Record<string, any>>("/api/verifications/sign-up", {
30
+ method: "POST",
31
+ body: { email },
32
+ });
33
+ }
34
+
35
+ function cancelInvite(id: string) {
36
+ return $fetch<Record<string, any>>(`/api/verifications/invite/id/${id}`, {
37
+ method: "DELETE",
38
+ });
39
+ }
40
+
16
41
  return {
17
42
  getVerifications,
43
+ inviteMember,
44
+ signUp,
45
+ cancelInvite,
18
46
  };
19
47
  }
package/nuxt.config.ts CHANGED
@@ -45,6 +45,36 @@ export default defineNuxtConfig({
45
45
  },
46
46
  ],
47
47
 
48
+ routeRules: {
49
+ "/api/apps/**": { proxy: `${process.env.API_CORE}/api/apps/**` },
50
+ "/api/auth/**": { proxy: `${process.env.API_CORE}/api/auth/**` },
51
+ "/api/users/**": { proxy: `${process.env.API_CORE}/api/users/**` },
52
+ "/api/apps/**": { proxy: `${process.env.API_CORE}/api/apps/**` },
53
+ "/api/permissions/**": {
54
+ proxy: `${process.env.API_CORE}/api/permissions/**`,
55
+ },
56
+ "/api/organizations/**": {
57
+ proxy: `${process.env.API_CORE}/api/organizations/**`,
58
+ },
59
+ "/api/members/**": { proxy: `${process.env.API_CORE}/api/members/**` },
60
+ "/api/teams/**": { proxy: `${process.env.API_CORE}/api/teams/**` },
61
+ "/api/entities/**": { proxy: `${process.env.API_CORE}/api/entities/**` },
62
+ "/api/workflows/**": { proxy: `${process.env.API_CORE}/api/workflows/**` },
63
+ "/api/roles/**": { proxy: `${process.env.API_CORE}/api/roles/**` },
64
+ "/api/promo-codes/**": {
65
+ proxy: `${process.env.API_CORE}/api/promo-codes/**`,
66
+ },
67
+ "/api/verifications/**": {
68
+ proxy: `${process.env.API_CORE}/api/verifications/**`,
69
+ },
70
+ "/api/files/**": {
71
+ proxy: `${process.env.API_CORE}/api/files/**`,
72
+ },
73
+ "/api/public/**": {
74
+ proxy: `${process.env.S3_BUCKET_ENDPOINT}/**`,
75
+ },
76
+ },
77
+
48
78
  vite: {
49
79
  vue: {
50
80
  template: {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@goweekdays/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.3.0",
5
+ "version": "1.3.2",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <v-row no-gutters class="fill-height" justify="center" align-content="center">
3
+ <v-col cols="12" class="mb-6">
4
+ <v-row no-gutters justify="center">
5
+ <nuxt-link
6
+ class="text-h2 font-weight-bold text-decoration-none"
7
+ style="color: unset"
8
+ :to="{ name: 'index' }"
9
+ >
10
+ GoWeekdays
11
+ </nuxt-link>
12
+ </v-row>
13
+ </v-col>
14
+
15
+ <v-col cols="12" lg="3" md="4" sm="6">
16
+ <v-form v-model="isValid" @submit.prevent="submit(email)">
17
+ <v-row no-gutters>
18
+ <v-col cols="12">
19
+ <v-row no-gutters>
20
+ <v-col cols="12" class="text-h6 font-weight-bold"> Email </v-col>
21
+ <v-col cols="12">
22
+ <v-text-field
23
+ v-model="email"
24
+ :rules="[requiredRule, emailRule]"
25
+ ></v-text-field>
26
+ </v-col>
27
+ </v-row>
28
+ </v-col>
29
+
30
+ <v-col v-if="message" cols="12" class="my-2 text-center font-italic">
31
+ {{ message }}
32
+ </v-col>
33
+
34
+ <v-col cols="12">
35
+ <v-row no-gutters justify="center">
36
+ <v-btn
37
+ type="submit"
38
+ variant="tonal"
39
+ :disabled="!isValid"
40
+ rounded="xl"
41
+ size="large"
42
+ >
43
+ submit
44
+ </v-btn>
45
+ </v-row>
46
+ </v-col>
47
+
48
+ <v-col cols="12" class="mt-2 text-center">
49
+ All good? <nuxt-link :to="{ name: 'login' }">Login</nuxt-link>
50
+ </v-col>
51
+ </v-row>
52
+ </v-form>
53
+ </v-col>
54
+ </v-row>
55
+ </template>
56
+
57
+ <script setup lang="ts">
58
+ definePageMeta({
59
+ layout: "plain",
60
+ });
61
+ const { requiredRule, emailRule } = useUtils();
62
+ const email = ref("");
63
+ const isValid = ref(false);
64
+
65
+ const { forgotPassword } = useLocalAuth();
66
+ const message = ref("");
67
+
68
+ async function submit(email = "") {
69
+ try {
70
+ const result: any = await forgotPassword(email);
71
+ message.value = result.message;
72
+ } catch (error: any) {
73
+ message.value = error.message;
74
+ }
75
+ }
76
+ </script>
@@ -0,0 +1,156 @@
1
+ <template>
2
+ <v-row
3
+ no-gutters
4
+ class="fill-height pa-8"
5
+ justify="center"
6
+ align-content="center"
7
+ >
8
+ <v-col cols="12" lg="3" md="4" sm="6">
9
+ <v-form
10
+ v-model="isValid"
11
+ @submit.prevent="submit({ email, password })"
12
+ :disabled="loading"
13
+ >
14
+ <v-row no-gutters>
15
+ <v-col cols="12">
16
+ <v-row no-gutters justify="center">
17
+ <nuxt-link
18
+ class="text-h3 text-sm-h2 text-md-h2 text-lg-h2 text-xl-h2 font-weight-bold text-decoration-none"
19
+ style="color: unset"
20
+ :to="{ name: 'index' }"
21
+ >
22
+ GoWeekdays
23
+ </nuxt-link>
24
+ </v-row>
25
+ </v-col>
26
+
27
+ <v-col cols="12" class="mt-6">
28
+ <v-row no-gutters>
29
+ <v-col cols="12" class="text-h6 font-weight-bold"> Email </v-col>
30
+ <v-col cols="12">
31
+ <v-text-field
32
+ v-model="email"
33
+ :rules="[requiredRule, emailRule]"
34
+ ></v-text-field>
35
+ </v-col>
36
+ </v-row>
37
+ </v-col>
38
+
39
+ <v-col cols="12">
40
+ <v-row no-gutters>
41
+ <v-col cols="12" class="text-h6 font-weight-bold">
42
+ Password
43
+ </v-col>
44
+ <v-col cols="12">
45
+ <InputPassword v-model="password" :rules="[requiredRule]" />
46
+ </v-col>
47
+ </v-row>
48
+ </v-col>
49
+
50
+ <v-col v-if="message" cols="12" class="my-2 text-center font-italic">
51
+ {{ message }}
52
+ </v-col>
53
+
54
+ <v-col cols="12" class="mt-4">
55
+ <v-row no-gutters justify="center">
56
+ <v-btn
57
+ block
58
+ type="submit"
59
+ variant="tonal"
60
+ :disabled="!isValid"
61
+ rounded="xl"
62
+ size="large"
63
+ class="text-none"
64
+ :loading="loading"
65
+ >
66
+ Login
67
+ </v-btn>
68
+ </v-row>
69
+ </v-col>
70
+
71
+ <v-col cols="12" class="text-center font-weight-bold mt-4">
72
+ <nuxt-link
73
+ :to="{ name: 'forgot-password' }"
74
+ class="text-decoration-none text-primary"
75
+ >
76
+ Forgot password?
77
+ </nuxt-link>
78
+ </v-col>
79
+
80
+ <v-col cols="12" class="my-4">
81
+ <v-divider></v-divider>
82
+ </v-col>
83
+
84
+ <v-col cols="12">
85
+ <v-row no-gutters justify="center">
86
+ <v-btn
87
+ block
88
+ variant="flat"
89
+ color="black"
90
+ rounded="xl"
91
+ size="large"
92
+ class="text-none"
93
+ :to="{ name: 'sign-up' }"
94
+ >
95
+ Create new account
96
+ </v-btn>
97
+ </v-row>
98
+ </v-col>
99
+ </v-row>
100
+ </v-form>
101
+ </v-col>
102
+ </v-row>
103
+ </template>
104
+
105
+ <script setup lang="ts">
106
+ definePageMeta({
107
+ layout: "plain",
108
+ });
109
+ const { requiredRule, emailRule } = useUtils();
110
+ const email = ref("");
111
+ const password = ref("");
112
+ const isValid = ref(false);
113
+
114
+ const { login } = useLocalAuth();
115
+
116
+ const message = ref("");
117
+
118
+ const loading = ref(false);
119
+
120
+ const { APP, cookieConfig } = useRuntimeConfig().public;
121
+
122
+ const { getByApp } = useMember();
123
+
124
+ async function submit({ email = "", password = "" } = {}) {
125
+ loading.value = true;
126
+ try {
127
+ await login({ email, password });
128
+
129
+ if (APP === "main") {
130
+ await navigateTo({ name: "feed" });
131
+ return;
132
+ }
133
+
134
+ if (APP === "admin") {
135
+ await navigateTo({ name: "home" });
136
+ return;
137
+ }
138
+
139
+ const userId = (useCookie("user", cookieConfig).value as string) ?? "";
140
+
141
+ const memberData = await getByApp({ app: APP, user: userId });
142
+
143
+ if (memberData && memberData.org) {
144
+ navigateTo({
145
+ name: "org-dashboard",
146
+ params: { org: memberData.org },
147
+ });
148
+ return;
149
+ }
150
+ } catch (error: any) {
151
+ message.value = error.response._data.message;
152
+ } finally {
153
+ loading.value = false;
154
+ }
155
+ }
156
+ </script>
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <v-row no-gutters class="fill-height" justify="center" align-content="center">
3
+ <v-col cols="12" class="mt-2 text-center font-weight-bold">
4
+ You have been logged out.
5
+ <nuxt-link :to="{ name: 'login' }">Login</nuxt-link>
6
+ </v-col>
7
+ </v-row>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ definePageMeta({
12
+ layout: "plain",
13
+ });
14
+
15
+ const { logout } = useLocalAuth();
16
+
17
+ logout();
18
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <v-row no-gutters class="fill-height" justify="center" align-content="center">
3
+ <v-col cols="12" class="mb-4">
4
+ <v-row justify="center" class="pa-4">
5
+ <span class="text-h5 font-weight-medium"> Member Suspended </span>
6
+ </v-row>
7
+ </v-col>
8
+
9
+ <span class="text-subtitle-2">
10
+ Your membership has been suspended. Please contact your organization
11
+ administrator for more information.
12
+ </span>
13
+
14
+ <v-col cols="12" class="mt-6">
15
+ <v-row no-gutters justify="center">
16
+ <v-btn
17
+ size="large"
18
+ class="text-none"
19
+ variant="flat"
20
+ color="black"
21
+ rounded
22
+ @click="navigateTo({ name: 'index' })"
23
+ >
24
+ Return to Landing Page
25
+ </v-btn>
26
+ </v-row>
27
+ </v-col>
28
+ </v-row>
29
+ </template>
30
+
31
+ <script setup lang="ts">
32
+ definePageMeta({
33
+ layout: "plain",
34
+ });
35
+
36
+ function createOrg() {
37
+ const { APP, APP_ORG } = useRuntimeConfig().public;
38
+ if (APP === "organization") {
39
+ navigateTo({ name: "organizations-create" });
40
+ } else {
41
+ navigateTo(`${APP_ORG}/organizations/create`, { external: true });
42
+ }
43
+ }
44
+ </script>