flowrix 1.0.1-beta.58 → 1.0.1-beta.59
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/module.json +1 -1
- package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.d.ts +40 -1
- package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.js +2 -2
- package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.d.ts +40 -1
- package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.js +2 -2
- package/dist/runtime/composables/Checkout/useCheckout.js +2 -2
- package/dist/runtime/composables/Checkout/useShippingAddress.js +2 -2
- package/dist/runtime/composables/Customer/useRegister.js +2 -2
- package/dist/runtime/composables/Header/useHeader.js +3 -2
- package/dist/runtime/composables/index.d.ts +1 -1
- package/dist/runtime/composables/index.js +1 -1
- package/dist/runtime/composables/useAddresses.js +2 -2
- package/dist/runtime/middleware/flowrix.js +11 -0
- package/dist/runtime/server/api/category/[...slug].js +9 -10
- package/dist/runtime/server/api/cmspost/all.js +1 -1
- package/dist/runtime/server/api/company/profile.js +7 -2
- package/dist/runtime/stores/auth.d.ts +1 -9
- package/dist/runtime/stores/auth.js +39 -7
- package/package.json +1 -1
- package/dist/runtime/composables/useAuth.d.ts +0 -45
- package/dist/runtime/composables/useAuth.js +0 -180
package/dist/module.json
CHANGED
|
@@ -6,7 +6,46 @@ declare global {
|
|
|
6
6
|
}
|
|
7
7
|
export default function (): {
|
|
8
8
|
checkoutStore: any;
|
|
9
|
-
user:
|
|
9
|
+
user: {
|
|
10
|
+
id: number;
|
|
11
|
+
fullname: string;
|
|
12
|
+
firstname: string;
|
|
13
|
+
lastname: string;
|
|
14
|
+
email: string;
|
|
15
|
+
avatar: string;
|
|
16
|
+
country_id: number | null;
|
|
17
|
+
country: {
|
|
18
|
+
id: number;
|
|
19
|
+
name: string;
|
|
20
|
+
emoji: string;
|
|
21
|
+
} | null;
|
|
22
|
+
state_id: number | null;
|
|
23
|
+
state: string | null;
|
|
24
|
+
suburb: string | null;
|
|
25
|
+
dob: string | null;
|
|
26
|
+
phone: string | null;
|
|
27
|
+
address: string | null;
|
|
28
|
+
mobile: string | null;
|
|
29
|
+
company: string | null;
|
|
30
|
+
addresses: {
|
|
31
|
+
id: number;
|
|
32
|
+
fullname: string | null;
|
|
33
|
+
firstname: string;
|
|
34
|
+
middlename: string | null;
|
|
35
|
+
lastname: string;
|
|
36
|
+
address: string;
|
|
37
|
+
suburb: string;
|
|
38
|
+
state: string | null;
|
|
39
|
+
state_id: number | null;
|
|
40
|
+
country: string;
|
|
41
|
+
country_id: number;
|
|
42
|
+
postcode: string;
|
|
43
|
+
mobile: string;
|
|
44
|
+
shipping: number;
|
|
45
|
+
billing: number;
|
|
46
|
+
}[];
|
|
47
|
+
created_at: string;
|
|
48
|
+
} | null;
|
|
10
49
|
ChangeCard: (token?: string) => void;
|
|
11
50
|
getpaymentMethod: (paymentMethod: string, inputData: any, totalPrice: string) => Promise<void>;
|
|
12
51
|
saveToCheckoutSession: (inputData: any) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useCheckoutStore } from "../../../stores/Checkout.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useAuthStore } from "../../../stores/auth.js";
|
|
3
3
|
export default function() {
|
|
4
4
|
const checkoutStore = useCheckoutStore();
|
|
5
|
-
const { user } =
|
|
5
|
+
const { user } = useAuthStore();
|
|
6
6
|
const payment = new PaymentJs();
|
|
7
7
|
const getpaymentMethod = async (paymentMethod, inputData, totalPrice) => {
|
|
8
8
|
try {
|
|
@@ -5,5 +5,44 @@ export default function (): {
|
|
|
5
5
|
opayoMonthValidations: (inputData: any) => void;
|
|
6
6
|
opayoYearValidations: () => void;
|
|
7
7
|
ChangeCard: (token?: string) => void;
|
|
8
|
-
user:
|
|
8
|
+
user: {
|
|
9
|
+
id: number;
|
|
10
|
+
fullname: string;
|
|
11
|
+
firstname: string;
|
|
12
|
+
lastname: string;
|
|
13
|
+
email: string;
|
|
14
|
+
avatar: string;
|
|
15
|
+
country_id: number | null;
|
|
16
|
+
country: {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
emoji: string;
|
|
20
|
+
} | null;
|
|
21
|
+
state_id: number | null;
|
|
22
|
+
state: string | null;
|
|
23
|
+
suburb: string | null;
|
|
24
|
+
dob: string | null;
|
|
25
|
+
phone: string | null;
|
|
26
|
+
address: string | null;
|
|
27
|
+
mobile: string | null;
|
|
28
|
+
company: string | null;
|
|
29
|
+
addresses: {
|
|
30
|
+
id: number;
|
|
31
|
+
fullname: string | null;
|
|
32
|
+
firstname: string;
|
|
33
|
+
middlename: string | null;
|
|
34
|
+
lastname: string;
|
|
35
|
+
address: string;
|
|
36
|
+
suburb: string;
|
|
37
|
+
state: string | null;
|
|
38
|
+
state_id: number | null;
|
|
39
|
+
country: string;
|
|
40
|
+
country_id: number;
|
|
41
|
+
postcode: string;
|
|
42
|
+
mobile: string;
|
|
43
|
+
shipping: number;
|
|
44
|
+
billing: number;
|
|
45
|
+
}[];
|
|
46
|
+
created_at: string;
|
|
47
|
+
} | null;
|
|
9
48
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useCheckoutStore } from "../../../stores/Checkout.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useAuthStore } from "../../../stores/auth.js";
|
|
3
3
|
export default function() {
|
|
4
4
|
const checkoutStore = useCheckoutStore();
|
|
5
|
-
const { user } =
|
|
5
|
+
const { user } = useAuthStore();
|
|
6
6
|
const getpaymentMethod = async (paymentMethod, inputData, totalPrice) => {
|
|
7
7
|
try {
|
|
8
8
|
inputData.paymentmethod = paymentMethod;
|
|
@@ -4,7 +4,7 @@ import { useCartStore } from "../../stores/Cart.js";
|
|
|
4
4
|
import { useCheckoutStore } from "../../stores/Checkout.js";
|
|
5
5
|
import { useCountry } from "../Extras/useCountry.js";
|
|
6
6
|
import { useRouter, useRoute } from "vue-router";
|
|
7
|
-
import {
|
|
7
|
+
import { useAuthStore } from "../../stores/auth.js";
|
|
8
8
|
export default function() {
|
|
9
9
|
const router = useRouter();
|
|
10
10
|
const route = useRoute();
|
|
@@ -12,7 +12,7 @@ export default function() {
|
|
|
12
12
|
user,
|
|
13
13
|
token,
|
|
14
14
|
isAuthenticated
|
|
15
|
-
} =
|
|
15
|
+
} = useAuthStore();
|
|
16
16
|
const { profile } = useCompanyProfile();
|
|
17
17
|
const cartStore = useCartStore();
|
|
18
18
|
const companyCountryId = computed(() => profile?.data.country_id || "");
|
|
@@ -3,7 +3,7 @@ import { useCheckoutStore } from "../../stores/Checkout.js";
|
|
|
3
3
|
import { useCountry } from "../Extras/useCountry.js";
|
|
4
4
|
import { useCompanyProfile } from "../../stores/useCompanyProfile.js";
|
|
5
5
|
import useStripe from "./PaymentMethods/useStripe.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useAuthStore } from "../../stores/auth.js";
|
|
7
7
|
export default function(inputData) {
|
|
8
8
|
const {
|
|
9
9
|
status,
|
|
@@ -16,7 +16,7 @@ export default function(inputData) {
|
|
|
16
16
|
signIn,
|
|
17
17
|
signOut,
|
|
18
18
|
refresh
|
|
19
|
-
} =
|
|
19
|
+
} = useAuthStore();
|
|
20
20
|
const AuthStore = ref();
|
|
21
21
|
const checkoutStore = useCheckoutStore();
|
|
22
22
|
const CountryData = useCountry().data;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ref } from "vue";
|
|
2
2
|
import { useRouter, useRoute } from "#vue-router";
|
|
3
|
-
import {
|
|
3
|
+
import { useAuthStore } from "../../stores/auth.js";
|
|
4
4
|
export default function() {
|
|
5
5
|
const router = useRouter();
|
|
6
6
|
const route = useRoute();
|
|
7
|
-
const { signUp } =
|
|
7
|
+
const { signUp } = useAuthStore();
|
|
8
8
|
const form_error = ref("");
|
|
9
9
|
const inputData = ref({ passwordStrengthValue: 0 });
|
|
10
10
|
const { showPassword, togglePassword } = useTogglePassword();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { defineAsyncComponent, ref, computed } from "vue";
|
|
2
|
-
import { useNavMenu, useCompanyProfile,
|
|
2
|
+
import { useNavMenu, useCompanyProfile, useCartStore, useSearchStore } from "#imports";
|
|
3
|
+
import { useAuthStore } from "../../stores/auth.js";
|
|
3
4
|
export default function() {
|
|
4
5
|
const wordpressUrl = import.meta.env.VITE_APP_WORDPRESS_URL;
|
|
5
6
|
const NavMenu = useNavMenu();
|
|
6
7
|
const CompanyProfile = useCompanyProfile();
|
|
7
|
-
const { user } =
|
|
8
|
+
const { user } = useAuthStore();
|
|
8
9
|
const cartStore = useCartStore();
|
|
9
10
|
const useSearch = useSearchStore();
|
|
10
11
|
const companyProfile = computed(() => CompanyProfile.profile);
|
|
@@ -25,6 +25,7 @@ export * from './Checkout/PaymentMethods/usePaypal.js';
|
|
|
25
25
|
export * from './Checkout/PaymentMethods/useStripe.js';
|
|
26
26
|
export * from './Checkout/PaymentMethods/useZippay.js';
|
|
27
27
|
export * from './Customer/useRegister.js';
|
|
28
|
+
export * from './Customer/useLogin.js';
|
|
28
29
|
export * from './Extras/useCountry.js';
|
|
29
30
|
export * from './Extras/useDateFormatter.js';
|
|
30
31
|
export * from './Extras/useNumberOnly.js';
|
|
@@ -55,7 +56,6 @@ export * from './SideBar/Filters/useSorting.js';
|
|
|
55
56
|
export { useAddresses } from './useAddresses.js';
|
|
56
57
|
export { useQuickView } from './Product/useQuickView.js';
|
|
57
58
|
export { useAddToCart } from './useAddToCart.js';
|
|
58
|
-
export { useAuth } from './useAuth.js';
|
|
59
59
|
export { useCards } from './useCards.js';
|
|
60
60
|
export { useClientApi } from './useClientApi.js';
|
|
61
61
|
export { useCountries } from './useCountries.js';
|
|
@@ -25,6 +25,7 @@ export * from "./Checkout/PaymentMethods/usePaypal.js";
|
|
|
25
25
|
export * from "./Checkout/PaymentMethods/useStripe.js";
|
|
26
26
|
export * from "./Checkout/PaymentMethods/useZippay.js";
|
|
27
27
|
export * from "./Customer/useRegister.js";
|
|
28
|
+
export * from "./Customer/useLogin.js";
|
|
28
29
|
export * from "./Extras/useCountry.js";
|
|
29
30
|
export * from "./Extras/useDateFormatter.js";
|
|
30
31
|
export * from "./Extras/useNumberOnly.js";
|
|
@@ -55,7 +56,6 @@ export * from "./SideBar/Filters/useSorting.js";
|
|
|
55
56
|
export { useAddresses } from "./useAddresses.js";
|
|
56
57
|
export { useQuickView } from "./Product/useQuickView.js";
|
|
57
58
|
export { useAddToCart } from "./useAddToCart.js";
|
|
58
|
-
export { useAuth } from "./useAuth.js";
|
|
59
59
|
export { useCards } from "./useCards.js";
|
|
60
60
|
export { useClientApi } from "./useClientApi.js";
|
|
61
61
|
export { useCountries } from "./useCountries.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import { useAddressesStore } from "../stores/addresses.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useAuthStore } from "../stores/auth.js";
|
|
4
4
|
import { useApi } from "../utils/api.js";
|
|
5
5
|
function formatErrorMessage(message) {
|
|
6
6
|
if (!message) return "An error occurred";
|
|
@@ -19,7 +19,7 @@ function formatErrorMessage(message) {
|
|
|
19
19
|
}
|
|
20
20
|
export function useAddresses() {
|
|
21
21
|
const store = useAddressesStore();
|
|
22
|
-
const { fetchProfile } =
|
|
22
|
+
const { fetchProfile } = useAuthStore();
|
|
23
23
|
const { post, patch, delete: deleteRequest } = useApi();
|
|
24
24
|
async function addAddress(userData) {
|
|
25
25
|
store.setLoading(true);
|
|
@@ -9,15 +9,26 @@ function getCookie(name) {
|
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
const parseCookies = (cookieString) => {
|
|
13
|
+
return Object.fromEntries(
|
|
14
|
+
cookieString.split(";").map((c) => {
|
|
15
|
+
const [key, ...v] = c.trim().split("=");
|
|
16
|
+
return [key, decodeURIComponent(v.join("="))];
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
};
|
|
12
20
|
async function request(method, config = {}, endpoint, options = {}) {
|
|
13
21
|
const FLOWRIX_API_KEY = config.public?.FLOWRIX_API_KEY || "";
|
|
14
22
|
const FLOWRIX_API_SECRET = config.public?.FLOWRIX_API_SECRET || "";
|
|
15
23
|
const FLOWRIX_API_ORIGIN = config.public?.FLOWRIX_API_ORIGIN || "";
|
|
16
24
|
let FLOWRIX_API_BASE = config.public?.FLOWRIX_API_BASE_V2 || "";
|
|
25
|
+
const cookiesObj = parseCookies(config.cookies || "");
|
|
26
|
+
const authToken = cookiesObj["authToken"];
|
|
17
27
|
const headers = {
|
|
18
28
|
"x-public-key": FLOWRIX_API_KEY,
|
|
19
29
|
"x-session-token": getCookie("x-session-token"),
|
|
20
30
|
"Access-Control-Expose-Headers": "x-session-token",
|
|
31
|
+
"authorization": `Bearer ${authToken}`,
|
|
21
32
|
"Origin": FLOWRIX_API_ORIGIN,
|
|
22
33
|
...options.headers
|
|
23
34
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
4
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "categories");
|
|
6
7
|
export const categoryCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -29,15 +30,13 @@ export default defineEventHandler(async (event) => {
|
|
|
29
30
|
} catch (error) {
|
|
30
31
|
}
|
|
31
32
|
try {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
});
|
|
33
|
+
const config = useRuntimeConfig();
|
|
34
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
35
|
+
const apiConfig = {
|
|
36
|
+
...config,
|
|
37
|
+
cookies: rawCookies
|
|
38
|
+
};
|
|
39
|
+
const category = await flowrixApi.get(`categories/${slug}`, apiConfig);
|
|
41
40
|
await ensureCacheDir();
|
|
42
41
|
await writeFile(filePath, JSON.stringify(category, null, 2), "utf-8");
|
|
43
42
|
return category;
|
|
@@ -3,8 +3,13 @@ import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
try {
|
|
6
|
-
|
|
7
|
-
const
|
|
6
|
+
const config = useRuntimeConfig();
|
|
7
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
8
|
+
const apiConfig = {
|
|
9
|
+
...config,
|
|
10
|
+
cookies: rawCookies
|
|
11
|
+
};
|
|
12
|
+
const companyProfile = await flowrixApi.get(`company/profile`, apiConfig);
|
|
8
13
|
return companyProfile;
|
|
9
14
|
} catch (error) {
|
|
10
15
|
setResponseStatus(event, 500);
|
|
@@ -51,12 +51,4 @@ export declare const useAuthStore: import("pinia").StoreDefinition<"auth", AuthS
|
|
|
51
51
|
getToken: (state: AuthState) => string | null;
|
|
52
52
|
isLoggedIn: (state: AuthState) => boolean;
|
|
53
53
|
isHydrated: (state: AuthState) => boolean;
|
|
54
|
-
}, {
|
|
55
|
-
setAuth({ user, token }: {
|
|
56
|
-
user: User;
|
|
57
|
-
token: string;
|
|
58
|
-
}): void;
|
|
59
|
-
loadAuth(): void;
|
|
60
|
-
logout(): void;
|
|
61
|
-
setHydrated(): void;
|
|
62
|
-
}>;
|
|
54
|
+
}, {}>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { defineStore } from "pinia";
|
|
2
|
+
import { flowrixApi } from "../middleware/flowrix.js";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
4
|
export const useAuthStore = defineStore("auth", {
|
|
3
5
|
state: () => ({
|
|
4
6
|
user: null,
|
|
@@ -7,13 +9,40 @@ export const useAuthStore = defineStore("auth", {
|
|
|
7
9
|
_hydrated: false
|
|
8
10
|
}),
|
|
9
11
|
actions: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
async userLogin(userFields) {
|
|
13
|
+
try {
|
|
14
|
+
const apiUrl = "login";
|
|
15
|
+
const config = useRuntimeConfig();
|
|
16
|
+
let rawCookies = "";
|
|
17
|
+
if (process.client) {
|
|
18
|
+
rawCookies = document.cookie || "";
|
|
19
|
+
}
|
|
20
|
+
const apiConfig = {
|
|
21
|
+
...config,
|
|
22
|
+
cookies: rawCookies
|
|
23
|
+
};
|
|
24
|
+
const response = await flowrixApi.post(
|
|
25
|
+
apiUrl,
|
|
26
|
+
apiConfig,
|
|
27
|
+
{
|
|
28
|
+
body: userFields
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
console.log(response);
|
|
32
|
+
if (response.status == "Success") {
|
|
33
|
+
const authTokenCookie = useCookie("authToken", {
|
|
34
|
+
sameSite: "none",
|
|
35
|
+
// cross-site requests
|
|
36
|
+
secure: true,
|
|
37
|
+
// must be https
|
|
38
|
+
path: "/",
|
|
39
|
+
expires: /* @__PURE__ */ new Date("2099-12-31")
|
|
40
|
+
});
|
|
41
|
+
authTokenCookie.value = response.data.access_token;
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return error.data;
|
|
17
46
|
}
|
|
18
47
|
},
|
|
19
48
|
loadAuth() {
|
|
@@ -55,5 +84,8 @@ export const useAuthStore = defineStore("auth", {
|
|
|
55
84
|
getToken: (state) => state.token,
|
|
56
85
|
isLoggedIn: (state) => state.isAuthenticated,
|
|
57
86
|
isHydrated: (state) => state._hydrated
|
|
87
|
+
},
|
|
88
|
+
persist: {
|
|
89
|
+
enabled: true
|
|
58
90
|
}
|
|
59
91
|
});
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type User } from '../stores/auth.js';
|
|
2
|
-
export interface AuthCredentials {
|
|
3
|
-
email: string;
|
|
4
|
-
password: string;
|
|
5
|
-
}
|
|
6
|
-
export interface ChangePasswordData {
|
|
7
|
-
current_password: string;
|
|
8
|
-
password: string;
|
|
9
|
-
password_confirmation: string;
|
|
10
|
-
}
|
|
11
|
-
export interface AuthResponse {
|
|
12
|
-
status: string;
|
|
13
|
-
message: string | Record<string, string[]> | null;
|
|
14
|
-
data: {
|
|
15
|
-
access_token: string;
|
|
16
|
-
token_type: string;
|
|
17
|
-
expires_in: number | null;
|
|
18
|
-
user: User;
|
|
19
|
-
} | null;
|
|
20
|
-
}
|
|
21
|
-
export declare function useAuth(): {
|
|
22
|
-
login: (credentials: AuthCredentials) => Promise<AuthResponse>;
|
|
23
|
-
register: (data: AuthCredentials & {
|
|
24
|
-
name?: string;
|
|
25
|
-
}) => Promise<AuthResponse>;
|
|
26
|
-
verifyEmail: (email: string) => Promise<AuthResponse>;
|
|
27
|
-
verifyToken: (email: string, token: string) => Promise<AuthResponse>;
|
|
28
|
-
resetPassword: (token: string, password: string, password_confirmation: string) => Promise<AuthResponse>;
|
|
29
|
-
logout: () => Promise<void>;
|
|
30
|
-
fetchProfile: () => Promise<User | null>;
|
|
31
|
-
updateProfile: (userData: any) => Promise<{
|
|
32
|
-
status: string;
|
|
33
|
-
message: string;
|
|
34
|
-
}>;
|
|
35
|
-
changePassword: (passwordData: ChangePasswordData) => Promise<{
|
|
36
|
-
status: string;
|
|
37
|
-
message: string;
|
|
38
|
-
}>;
|
|
39
|
-
initializeAuth: () => void;
|
|
40
|
-
formatErrorMessage: (message: string | Record<string, string[]> | null) => string;
|
|
41
|
-
user: import("vue").ComputedRef<User | null>;
|
|
42
|
-
token: import("vue").ComputedRef<string | null>;
|
|
43
|
-
isAuthenticated: import("vue").ComputedRef<boolean>;
|
|
44
|
-
isHydrated: import("vue").ComputedRef<boolean>;
|
|
45
|
-
};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
2
|
-
import { useAuthStore } from "../stores/auth.js";
|
|
3
|
-
import { useApi } from "../utils/api.js";
|
|
4
|
-
export function useAuth() {
|
|
5
|
-
const authStore = useAuthStore();
|
|
6
|
-
const { post, get } = useApi();
|
|
7
|
-
function formatErrorMessage(message) {
|
|
8
|
-
if (!message) return "";
|
|
9
|
-
if (typeof message === "string") {
|
|
10
|
-
return message;
|
|
11
|
-
}
|
|
12
|
-
const errorMessages = [];
|
|
13
|
-
for (const [, errors] of Object.entries(message)) {
|
|
14
|
-
if (Array.isArray(errors)) {
|
|
15
|
-
errorMessages.push(...errors);
|
|
16
|
-
} else {
|
|
17
|
-
errorMessages.push(String(errors));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return errorMessages.join(", ");
|
|
21
|
-
}
|
|
22
|
-
async function login(credentials) {
|
|
23
|
-
try {
|
|
24
|
-
const response = await post("/login", credentials);
|
|
25
|
-
if (response.status === "Success" && response.data?.access_token && response.data?.user) {
|
|
26
|
-
authStore.setAuth({
|
|
27
|
-
user: response.data.user,
|
|
28
|
-
token: response.data.access_token
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return response;
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error("Login error:", error);
|
|
34
|
-
const message = error.data ? formatErrorMessage(error.data.message) : error.message || "Login failed";
|
|
35
|
-
return {
|
|
36
|
-
status: "Error",
|
|
37
|
-
message,
|
|
38
|
-
data: null
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async function register(data) {
|
|
43
|
-
try {
|
|
44
|
-
const response = await post("/mystore/customer/create", data);
|
|
45
|
-
return response;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error("Registration error:", error);
|
|
48
|
-
const message = error.data ? formatErrorMessage(error.data.message) : error.message || "Registration failed";
|
|
49
|
-
return {
|
|
50
|
-
status: "Error",
|
|
51
|
-
message,
|
|
52
|
-
data: null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function verifyEmail(email) {
|
|
57
|
-
try {
|
|
58
|
-
const response = await post("/verify-email", { email });
|
|
59
|
-
return response;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error("Verify email error:", error);
|
|
62
|
-
const message = error.data ? formatErrorMessage(error.data.message) : error.message || "email verification failed";
|
|
63
|
-
return {
|
|
64
|
-
status: "Error",
|
|
65
|
-
message,
|
|
66
|
-
data: null
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async function verifyToken(email, token) {
|
|
71
|
-
try {
|
|
72
|
-
const response = await post("/verify-token", { email, token });
|
|
73
|
-
return response;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error("Verify token error:", error);
|
|
76
|
-
const message = error.data ? formatErrorMessage(error.data.message) : error.message || "Token verification failed";
|
|
77
|
-
return {
|
|
78
|
-
status: "Error",
|
|
79
|
-
message,
|
|
80
|
-
data: null
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async function resetPassword(token, password, password_confirmation) {
|
|
85
|
-
try {
|
|
86
|
-
const response = await post("/reset-password", {
|
|
87
|
-
token,
|
|
88
|
-
password,
|
|
89
|
-
password_confirmation
|
|
90
|
-
});
|
|
91
|
-
return response;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error("Reset password error:", error);
|
|
94
|
-
const message = error.data ? formatErrorMessage(error.data.message) : error.message || "Password reset failed";
|
|
95
|
-
return {
|
|
96
|
-
status: "Error",
|
|
97
|
-
message,
|
|
98
|
-
data: null
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function logout() {
|
|
103
|
-
try {
|
|
104
|
-
await post("/mystore/customer/logout", {});
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error("Logout API failed:", error);
|
|
107
|
-
} finally {
|
|
108
|
-
authStore.logout();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async function fetchProfile() {
|
|
112
|
-
try {
|
|
113
|
-
const response = await get("/mystore/customer/profile");
|
|
114
|
-
if (response.status === "Success" && response.data) {
|
|
115
|
-
authStore.user = response.data;
|
|
116
|
-
if (import.meta.client) {
|
|
117
|
-
localStorage.setItem("auth_user", JSON.stringify(response.data));
|
|
118
|
-
}
|
|
119
|
-
return response.data;
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error("Fetch profile failed:", error);
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async function updateProfile(userData) {
|
|
128
|
-
try {
|
|
129
|
-
const response = await post("/mystore/customer/profile/update", userData);
|
|
130
|
-
if (response.status === "Success") {
|
|
131
|
-
await fetchProfile();
|
|
132
|
-
return { status: response.status, message: response.message || "Profile Updated Successfully" };
|
|
133
|
-
} else {
|
|
134
|
-
const errorMessage = formatErrorMessage(response.message);
|
|
135
|
-
throw new Error(errorMessage);
|
|
136
|
-
}
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error("Update profile error:", error);
|
|
139
|
-
const errorMessage = error.data ? formatErrorMessage(error.data.message) : error.message || "Failed to update profile";
|
|
140
|
-
throw new Error(errorMessage);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function changePassword(passwordData) {
|
|
144
|
-
try {
|
|
145
|
-
const response = await post("/mystore/customer/change-password", passwordData);
|
|
146
|
-
if (response.status === "Success") {
|
|
147
|
-
return { status: "Success", message: "Password updated successfully" };
|
|
148
|
-
} else {
|
|
149
|
-
const errorMessage = formatErrorMessage(response.message);
|
|
150
|
-
throw new Error(errorMessage);
|
|
151
|
-
}
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.error("Change password error:", error);
|
|
154
|
-
const errorMessage = error.data ? formatErrorMessage(error.data.message) : error.message || "Failed to change password";
|
|
155
|
-
throw new Error(errorMessage);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const initializeAuth = () => {
|
|
159
|
-
if (import.meta.client && !authStore.isHydrated) {
|
|
160
|
-
authStore.loadAuth();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
return {
|
|
164
|
-
login,
|
|
165
|
-
register,
|
|
166
|
-
verifyEmail,
|
|
167
|
-
verifyToken,
|
|
168
|
-
resetPassword,
|
|
169
|
-
logout,
|
|
170
|
-
fetchProfile,
|
|
171
|
-
updateProfile,
|
|
172
|
-
changePassword,
|
|
173
|
-
initializeAuth,
|
|
174
|
-
formatErrorMessage,
|
|
175
|
-
user: computed(() => authStore.getUser),
|
|
176
|
-
token: computed(() => authStore.getToken),
|
|
177
|
-
isAuthenticated: computed(() => authStore.isLoggedIn),
|
|
178
|
-
isHydrated: computed(() => authStore.isHydrated)
|
|
179
|
-
};
|
|
180
|
-
}
|