@raxonltd/raxon-core 1.1.13 → 1.1.14
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/core/context/security.context.tsx +9 -5
- package/core/feature/auth/hook/use.auth.tsx +7 -6
- package/core/feature/cart/hook/use.cart.tsx +3 -0
- package/core/raxon.context.tsx +7 -0
- package/core/util/nexine.axios.tsx +3 -2
- package/core/util/storage.keys.ts +39 -0
- package/dist/core/context/security.context.d.ts.map +1 -1
- package/dist/core/context/security.context.js +8 -5
- package/dist/core/feature/auth/hook/use.auth.d.ts.map +1 -1
- package/dist/core/feature/auth/hook/use.auth.js +7 -6
- package/dist/core/raxon.context.d.ts +3 -1
- package/dist/core/raxon.context.d.ts.map +1 -1
- package/dist/core/raxon.context.js +5 -3
- package/dist/core/util/nexine.axios.d.ts.map +1 -1
- package/dist/core/util/nexine.axios.js +3 -2
- package/dist/core/util/storage.keys.d.ts +9 -0
- package/dist/core/util/storage.keys.d.ts.map +1 -0
- package/dist/core/util/storage.keys.js +35 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { useRouter, usePathname } from 'next/navigation';
|
|
|
5
5
|
import { LoginType, User } from '@/core/interface/prisma.interface';
|
|
6
6
|
import { useAuth } from '@/core/feature/auth/hook/use.auth';
|
|
7
7
|
import { useProfile } from '@/core/feature/profile/hook/use.profile';
|
|
8
|
+
import { getToken, getTokenChangedEventName, getTokenStorageKey, removeToken } from '@/core/util/storage.keys';
|
|
8
9
|
|
|
9
10
|
export interface SecurityState {
|
|
10
11
|
profile: User | null | undefined;
|
|
@@ -58,7 +59,7 @@ export const useSecurityState = (): SecurityState => {
|
|
|
58
59
|
|
|
59
60
|
const checkToken = useCallback(() => {
|
|
60
61
|
if (typeof window !== 'undefined') {
|
|
61
|
-
const token =
|
|
62
|
+
const token = getToken();
|
|
62
63
|
if (token && token.trim() !== '' && token.length > 3) {
|
|
63
64
|
setAuthLoading(true);
|
|
64
65
|
tokenCheck(undefined, {
|
|
@@ -76,7 +77,7 @@ export const useSecurityState = (): SecurityState => {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
if (isInvalidTokenError(error)) {
|
|
79
|
-
|
|
80
|
+
removeToken();
|
|
80
81
|
ensureGuestLogin();
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
@@ -97,8 +98,11 @@ export const useSecurityState = (): SecurityState => {
|
|
|
97
98
|
|
|
98
99
|
useEffect(() => {
|
|
99
100
|
if (typeof window !== 'undefined') {
|
|
101
|
+
const tokenStorageKey = getTokenStorageKey();
|
|
102
|
+
const tokenChangedEvent = getTokenChangedEventName();
|
|
103
|
+
|
|
100
104
|
const handleStorageChange = (e: StorageEvent) => {
|
|
101
|
-
if (e.key ===
|
|
105
|
+
if (e.key === tokenStorageKey) {
|
|
102
106
|
checkToken();
|
|
103
107
|
}
|
|
104
108
|
};
|
|
@@ -108,11 +112,11 @@ export const useSecurityState = (): SecurityState => {
|
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
window.addEventListener('storage', handleStorageChange);
|
|
111
|
-
window.addEventListener(
|
|
115
|
+
window.addEventListener(tokenChangedEvent, handleCustomStorageChange);
|
|
112
116
|
|
|
113
117
|
return () => {
|
|
114
118
|
window.removeEventListener('storage', handleStorageChange);
|
|
115
|
-
window.removeEventListener(
|
|
119
|
+
window.removeEventListener(tokenChangedEvent, handleCustomStorageChange);
|
|
116
120
|
};
|
|
117
121
|
}
|
|
118
122
|
}, [checkToken]);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nexineAxios } from "@/core/util/nexine.axios";
|
|
2
|
+
import { dispatchTokenChanged, removeToken, setToken } from "@/core/util/storage.keys";
|
|
2
3
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
4
|
import { useEffect, useState } from "react";
|
|
4
5
|
import toast from "react-hot-toast";
|
|
@@ -40,7 +41,7 @@ export const useAuth = () => {
|
|
|
40
41
|
return nexineAxios.post('/auth/login/email', data)
|
|
41
42
|
},
|
|
42
43
|
onSuccess: (response: any) => {
|
|
43
|
-
|
|
44
|
+
setToken(response.data.token);
|
|
44
45
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
45
46
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
46
47
|
queryClient.invalidateQueries({ queryKey: ["cart"] });
|
|
@@ -48,7 +49,7 @@ export const useAuth = () => {
|
|
|
48
49
|
// Login success event'ini tetikle
|
|
49
50
|
if (typeof window !== 'undefined') {
|
|
50
51
|
window.dispatchEvent(new Event(LOGIN_SUCCESS_EVENT));
|
|
51
|
-
|
|
52
|
+
dispatchTokenChanged();
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
})
|
|
@@ -59,7 +60,7 @@ export const useAuth = () => {
|
|
|
59
60
|
return nexineAxios.post('/auth/login/guest')
|
|
60
61
|
},
|
|
61
62
|
onSuccess: (response: any) => {
|
|
62
|
-
|
|
63
|
+
setToken(response.data.token);
|
|
63
64
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
64
65
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
65
66
|
queryClient.invalidateQueries({ queryKey: ["cart"] });
|
|
@@ -68,7 +69,7 @@ export const useAuth = () => {
|
|
|
68
69
|
// Login success event'ini tetikle
|
|
69
70
|
if (typeof window !== 'undefined') {
|
|
70
71
|
window.dispatchEvent(new Event(LOGIN_SUCCESS_EVENT));
|
|
71
|
-
|
|
72
|
+
dispatchTokenChanged();
|
|
72
73
|
}
|
|
73
74
|
},
|
|
74
75
|
})
|
|
@@ -126,14 +127,14 @@ export const useAuth = () => {
|
|
|
126
127
|
})
|
|
127
128
|
},
|
|
128
129
|
logout: () => {
|
|
129
|
-
|
|
130
|
+
removeToken();
|
|
130
131
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
131
132
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
132
133
|
|
|
133
134
|
// Logout event'ini tetikle
|
|
134
135
|
if (typeof window !== 'undefined') {
|
|
135
136
|
window.dispatchEvent(new Event(LOGOUT_EVENT));
|
|
136
|
-
|
|
137
|
+
dispatchTokenChanged();
|
|
137
138
|
window.location.reload();
|
|
138
139
|
}
|
|
139
140
|
}
|
|
@@ -79,6 +79,9 @@ export const useCart = () => {
|
|
|
79
79
|
const response = await nexineAxios.post('/customer/basket/me/item', data);
|
|
80
80
|
return response.data;
|
|
81
81
|
},
|
|
82
|
+
onSuccess: () => {
|
|
83
|
+
queryClient.invalidateQueries({ queryKey: CART_QUERY_KEY });
|
|
84
|
+
},
|
|
82
85
|
onError: (error, _newData, context: any) => {
|
|
83
86
|
if (context?.previousCarts) {
|
|
84
87
|
context.previousCarts.forEach(([key, value]: any) => {
|
package/core/raxon.context.tsx
CHANGED
|
@@ -29,6 +29,7 @@ import { useCartState, CartState } from "@/core/context/cart.context";
|
|
|
29
29
|
import { AnalyticEventProvider } from "@/core/feature/analytic-event/analytic.event.context";
|
|
30
30
|
import { RaxonContextBrand } from "./interface/context.interface";
|
|
31
31
|
import { RaxonBootstrapPayload } from "./interface/bootstrap.interface";
|
|
32
|
+
import { DEFAULT_STORAGE_PREFIX } from "./util/storage.keys";
|
|
32
33
|
|
|
33
34
|
export const RaxonContext = createContext<RaxonContextType | undefined>(undefined);
|
|
34
35
|
|
|
@@ -72,6 +73,8 @@ export interface RaxonProviderProps {
|
|
|
72
73
|
children: React.ReactNode;
|
|
73
74
|
apiKey: string;
|
|
74
75
|
apiUrl: string;
|
|
76
|
+
/** localStorage anahtarları için önek. Varsayılan: `raxon` (ör. `raxon-token`) */
|
|
77
|
+
storagePrefix?: string;
|
|
75
78
|
productPathPrefix?: string;
|
|
76
79
|
analyticAutoTrack?: boolean;
|
|
77
80
|
/** Varsayılan: `/api/bootstrap` — Next.js BFF veya özel proxy */
|
|
@@ -120,6 +123,7 @@ const RaxonProviderInner = ({
|
|
|
120
123
|
children,
|
|
121
124
|
apiKey,
|
|
122
125
|
apiUrl,
|
|
126
|
+
storagePrefix = DEFAULT_STORAGE_PREFIX,
|
|
123
127
|
productPathPrefix,
|
|
124
128
|
analyticAutoTrack,
|
|
125
129
|
bootstrapUrl = "/api/bootstrap",
|
|
@@ -142,6 +146,7 @@ const RaxonProviderInner = ({
|
|
|
142
146
|
if (typeof window !== "undefined") {
|
|
143
147
|
(window as any).__RAXON_API_KEY__ = apiKey;
|
|
144
148
|
(window as any).__RAXON_API_URL__ = apiUrl;
|
|
149
|
+
(window as any).__RAXON_STORAGE_PREFIX__ = storagePrefix;
|
|
145
150
|
nexineAxios.defaults.baseURL = apiUrl;
|
|
146
151
|
nexineAxios.defaults.headers.common["x-api-key"] = apiKey;
|
|
147
152
|
}
|
|
@@ -224,6 +229,7 @@ export const RaxonProvider = ({
|
|
|
224
229
|
children,
|
|
225
230
|
apiKey,
|
|
226
231
|
apiUrl,
|
|
232
|
+
storagePrefix,
|
|
227
233
|
productPathPrefix,
|
|
228
234
|
analyticAutoTrack,
|
|
229
235
|
bootstrapUrl,
|
|
@@ -236,6 +242,7 @@ export const RaxonProvider = ({
|
|
|
236
242
|
<RaxonProviderInner
|
|
237
243
|
apiKey={apiKey}
|
|
238
244
|
apiUrl={apiUrl}
|
|
245
|
+
storagePrefix={storagePrefix}
|
|
239
246
|
productPathPrefix={productPathPrefix}
|
|
240
247
|
analyticAutoTrack={analyticAutoTrack}
|
|
241
248
|
bootstrapUrl={bootstrapUrl}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { toast } from 'react-hot-toast';
|
|
3
|
+
import { getToken, removeToken } from '@/core/util/storage.keys';
|
|
3
4
|
|
|
4
5
|
export const nexineAxios = axios.create({
|
|
5
6
|
baseURL: typeof window !== 'undefined' ? (window as any).__RAXON_API_URL__ : process.env.NEXT_PUBLIC_API_URL,
|
|
@@ -39,7 +40,7 @@ nexineAxios.interceptors.request.use(config => {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
if (typeof window !== 'undefined') {
|
|
42
|
-
const token =
|
|
43
|
+
const token = getToken();
|
|
43
44
|
if (token) {
|
|
44
45
|
config.headers.Authorization = `Bearer ${token}`;
|
|
45
46
|
}
|
|
@@ -83,7 +84,7 @@ nexineAxios.interceptors.response.use(
|
|
|
83
84
|
|
|
84
85
|
// Token'ı temizle
|
|
85
86
|
if (typeof window !== 'undefined') {
|
|
86
|
-
|
|
87
|
+
removeToken();
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
// /auth/me endpoint'inde toast gösterme (SecurityContext yönetiyor)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const DEFAULT_STORAGE_PREFIX = 'raxon';
|
|
2
|
+
|
|
3
|
+
const TOKEN_SUFFIX = '-token';
|
|
4
|
+
const TOKEN_CHANGED_SUFFIX = '-token-changed';
|
|
5
|
+
|
|
6
|
+
export const getStoragePrefix = (): string => {
|
|
7
|
+
if (typeof window !== 'undefined') {
|
|
8
|
+
return (window as any).__RAXON_STORAGE_PREFIX__ || DEFAULT_STORAGE_PREFIX;
|
|
9
|
+
}
|
|
10
|
+
return DEFAULT_STORAGE_PREFIX;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getTokenStorageKey = (): string => {
|
|
14
|
+
return `${getStoragePrefix()}${TOKEN_SUFFIX}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getTokenChangedEventName = (): string => {
|
|
18
|
+
return `${getStoragePrefix()}${TOKEN_CHANGED_SUFFIX}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getToken = (): string | null => {
|
|
22
|
+
if (typeof window === 'undefined') return null;
|
|
23
|
+
return localStorage.getItem(getTokenStorageKey());
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const setToken = (token: string): void => {
|
|
27
|
+
if (typeof window === 'undefined') return;
|
|
28
|
+
localStorage.setItem(getTokenStorageKey(), token);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const removeToken = (): void => {
|
|
32
|
+
if (typeof window === 'undefined') return;
|
|
33
|
+
localStorage.removeItem(getTokenStorageKey());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const dispatchTokenChanged = (): void => {
|
|
37
|
+
if (typeof window === 'undefined') return;
|
|
38
|
+
window.dispatchEvent(new Event(getTokenChangedEventName()));
|
|
39
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.context.d.ts","sourceRoot":"","sources":["../../../core/context/security.context.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,IAAI,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"security.context.d.ts","sourceRoot":"","sources":["../../../core/context/security.context.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAKpE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,gBAAgB,QAAO,aA0InC,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { useRouter, usePathname } from 'next/navigation';
|
|
|
4
4
|
import { LoginType } from '../interface/prisma.interface';
|
|
5
5
|
import { useAuth } from '../feature/auth/hook/use.auth';
|
|
6
6
|
import { useProfile } from '../feature/profile/hook/use.profile';
|
|
7
|
+
import { getToken, getTokenChangedEventName, getTokenStorageKey, removeToken } from '../util/storage.keys';
|
|
7
8
|
export const useSecurityState = () => {
|
|
8
9
|
const router = useRouter();
|
|
9
10
|
const pathname = usePathname();
|
|
@@ -41,7 +42,7 @@ export const useSecurityState = () => {
|
|
|
41
42
|
}, [loginGuest]);
|
|
42
43
|
const checkToken = useCallback(() => {
|
|
43
44
|
if (typeof window !== 'undefined') {
|
|
44
|
-
const token =
|
|
45
|
+
const token = getToken();
|
|
45
46
|
if (token && token.trim() !== '' && token.length > 3) {
|
|
46
47
|
setAuthLoading(true);
|
|
47
48
|
tokenCheck(undefined, {
|
|
@@ -58,7 +59,7 @@ export const useSecurityState = () => {
|
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
if (isInvalidTokenError(error)) {
|
|
61
|
-
|
|
62
|
+
removeToken();
|
|
62
63
|
ensureGuestLogin();
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
@@ -77,8 +78,10 @@ export const useSecurityState = () => {
|
|
|
77
78
|
}, [checkToken]);
|
|
78
79
|
useEffect(() => {
|
|
79
80
|
if (typeof window !== 'undefined') {
|
|
81
|
+
const tokenStorageKey = getTokenStorageKey();
|
|
82
|
+
const tokenChangedEvent = getTokenChangedEventName();
|
|
80
83
|
const handleStorageChange = (e) => {
|
|
81
|
-
if (e.key ===
|
|
84
|
+
if (e.key === tokenStorageKey) {
|
|
82
85
|
checkToken();
|
|
83
86
|
}
|
|
84
87
|
};
|
|
@@ -86,10 +89,10 @@ export const useSecurityState = () => {
|
|
|
86
89
|
checkToken();
|
|
87
90
|
};
|
|
88
91
|
window.addEventListener('storage', handleStorageChange);
|
|
89
|
-
window.addEventListener(
|
|
92
|
+
window.addEventListener(tokenChangedEvent, handleCustomStorageChange);
|
|
90
93
|
return () => {
|
|
91
94
|
window.removeEventListener('storage', handleStorageChange);
|
|
92
|
-
window.removeEventListener(
|
|
95
|
+
window.removeEventListener(tokenChangedEvent, handleCustomStorageChange);
|
|
93
96
|
};
|
|
94
97
|
}
|
|
95
98
|
}, [checkToken]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.auth.d.ts","sourceRoot":"","sources":["../../../../../core/feature/auth/hook/use.auth.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use.auth.d.ts","sourceRoot":"","sources":["../../../../../core/feature/auth/hook/use.auth.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,sBAAsB,CAAC;AAChD,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAE9D,eAAO,MAAM,OAAO;;;;;;;;kBAoEiC,MAAM;oBAAc,MAAM;;;;eAmBnC,MAAM;;;eAWN,MAAM;cAAQ,MAAM;;;eAYpB,MAAM;cAAQ,MAAM;kBAAY,MAAM;;;CAqBjF,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nexineAxios } from "../../../util/nexine.axios";
|
|
2
|
+
import { dispatchTokenChanged, removeToken, setToken } from "../../../util/storage.keys";
|
|
2
3
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
4
|
// Auth event'leri için custom eventler
|
|
4
5
|
export const LOGOUT_EVENT = 'intermarkt-logout';
|
|
@@ -30,14 +31,14 @@ export const useAuth = () => {
|
|
|
30
31
|
return nexineAxios.post('/auth/login/email', data);
|
|
31
32
|
},
|
|
32
33
|
onSuccess: (response) => {
|
|
33
|
-
|
|
34
|
+
setToken(response.data.token);
|
|
34
35
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
35
36
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
36
37
|
queryClient.invalidateQueries({ queryKey: ["cart"] });
|
|
37
38
|
// Login success event'ini tetikle
|
|
38
39
|
if (typeof window !== 'undefined') {
|
|
39
40
|
window.dispatchEvent(new Event(LOGIN_SUCCESS_EVENT));
|
|
40
|
-
|
|
41
|
+
dispatchTokenChanged();
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
});
|
|
@@ -48,14 +49,14 @@ export const useAuth = () => {
|
|
|
48
49
|
return nexineAxios.post('/auth/login/guest');
|
|
49
50
|
},
|
|
50
51
|
onSuccess: (response) => {
|
|
51
|
-
|
|
52
|
+
setToken(response.data.token);
|
|
52
53
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
53
54
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
54
55
|
queryClient.invalidateQueries({ queryKey: ["cart"] });
|
|
55
56
|
// Login success event'ini tetikle
|
|
56
57
|
if (typeof window !== 'undefined') {
|
|
57
58
|
window.dispatchEvent(new Event(LOGIN_SUCCESS_EVENT));
|
|
58
|
-
|
|
59
|
+
dispatchTokenChanged();
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
62
|
});
|
|
@@ -108,13 +109,13 @@ export const useAuth = () => {
|
|
|
108
109
|
});
|
|
109
110
|
},
|
|
110
111
|
logout: () => {
|
|
111
|
-
|
|
112
|
+
removeToken();
|
|
112
113
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
113
114
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
114
115
|
// Logout event'ini tetikle
|
|
115
116
|
if (typeof window !== 'undefined') {
|
|
116
117
|
window.dispatchEvent(new Event(LOGOUT_EVENT));
|
|
117
|
-
|
|
118
|
+
dispatchTokenChanged();
|
|
118
119
|
window.location.reload();
|
|
119
120
|
}
|
|
120
121
|
}
|
|
@@ -43,6 +43,8 @@ export interface RaxonProviderProps {
|
|
|
43
43
|
children: React.ReactNode;
|
|
44
44
|
apiKey: string;
|
|
45
45
|
apiUrl: string;
|
|
46
|
+
/** localStorage anahtarları için önek. Varsayılan: `raxon` (ör. `raxon-token`) */
|
|
47
|
+
storagePrefix?: string;
|
|
46
48
|
productPathPrefix?: string;
|
|
47
49
|
analyticAutoTrack?: boolean;
|
|
48
50
|
/** Varsayılan: `/api/bootstrap` — Next.js BFF veya özel proxy */
|
|
@@ -50,7 +52,7 @@ export interface RaxonProviderProps {
|
|
|
50
52
|
/** SSR ile layout'tan geçirilen bootstrap verisi */
|
|
51
53
|
initialBootstrapData?: RaxonBootstrapPayload | null;
|
|
52
54
|
}
|
|
53
|
-
export declare const RaxonProvider: ({ children, apiKey, apiUrl, productPathPrefix, analyticAutoTrack, bootstrapUrl, initialBootstrapData, }: RaxonProviderProps) => import("react").JSX.Element;
|
|
55
|
+
export declare const RaxonProvider: ({ children, apiKey, apiUrl, storagePrefix, productPathPrefix, analyticAutoTrack, bootstrapUrl, initialBootstrapData, }: RaxonProviderProps) => import("react").JSX.Element;
|
|
54
56
|
export declare const useRaxon: () => RaxonContextType;
|
|
55
57
|
export {};
|
|
56
58
|
//# sourceMappingURL=raxon.context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raxon.context.d.ts","sourceRoot":"","sources":["../../core/raxon.context.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,WAAW,EACX,MAAM,EACN,QAAQ,EAER,QAAQ,EACR,UAAU,EACV,cAAc,EACd,WAAW,EACX,GAAG,EACH,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,MAAM,EACN,IAAI,EACL,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAa,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAiC,gCAAgC,EAAE,MAAM,0DAA0D,CAAC;AAG3I,OAAO,EAAgB,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"raxon.context.d.ts","sourceRoot":"","sources":["../../core/raxon.context.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,WAAW,EACX,MAAM,EACN,QAAQ,EAER,QAAQ,EACR,UAAU,EACV,cAAc,EACd,WAAW,EACX,GAAG,EACH,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,MAAM,EACN,IAAI,EACL,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAa,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAiC,gCAAgC,EAAE,MAAM,0DAA0D,CAAC;AAG3I,OAAO,EAAgB,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,eAAO,MAAM,YAAY,2CAAyD,CAAC;AAGnF,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,cAAc,EAAE,QAAQ,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,iBAAiB,EAAE,UAAU,EAAE,CAAC;IAChC,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,YAAY,EAAE,QAAQ,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,CAAC;IACX,IAAI,EAAE,IAAI,EAAE,CAAC;IACb,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC,aAAa,EAAE,aAAa,EAAE,CAAC;IAC/B,qBAAqB,EAAE,cAAc,GAAG,IAAI,CAAC;IAC7C,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACnD,gCAAgC,EAAE,KAAK,CAAC,SAAS,CAAC,gCAAgC,GAAG,IAAI,CAAC,CAAC;CAC5F;AAED,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB,EAAE,SAAS;IACrE,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACrD;AAgJD,eAAO,MAAM,aAAa,GAAI,wHAS3B,kBAAkB,gCAkBpB,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,gBAM3B,CAAC"}
|
|
@@ -9,6 +9,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
9
9
|
import { useSecurityState } from "./context/security.context";
|
|
10
10
|
import { useCartState } from "./context/cart.context";
|
|
11
11
|
import { AnalyticEventProvider } from "./feature/analytic-event/analytic.event.context";
|
|
12
|
+
import { DEFAULT_STORAGE_PREFIX } from "./util/storage.keys";
|
|
12
13
|
export const RaxonContext = createContext(undefined);
|
|
13
14
|
function normalizeBootstrapPayload(raxon) {
|
|
14
15
|
if (!raxon)
|
|
@@ -43,7 +44,7 @@ function normalizeBootstrapPayload(raxon) {
|
|
|
43
44
|
brand: raxon.brand ?? [],
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
|
-
const RaxonProviderInner = ({ children, apiKey, apiUrl, productPathPrefix, analyticAutoTrack, bootstrapUrl = "/api/bootstrap", initialBootstrapData = null, }) => {
|
|
47
|
+
const RaxonProviderInner = ({ children, apiKey, apiUrl, storagePrefix = DEFAULT_STORAGE_PREFIX, productPathPrefix, analyticAutoTrack, bootstrapUrl = "/api/bootstrap", initialBootstrapData = null, }) => {
|
|
47
48
|
const initialNormalized = useMemo(() => normalizeBootstrapPayload(initialBootstrapData), [initialBootstrapData]);
|
|
48
49
|
const [raxon, setRaxon] = useState(initialBootstrapData ?? null);
|
|
49
50
|
const [isLoading, setIsLoading] = useState(!initialNormalized);
|
|
@@ -53,6 +54,7 @@ const RaxonProviderInner = ({ children, apiKey, apiUrl, productPathPrefix, analy
|
|
|
53
54
|
if (typeof window !== "undefined") {
|
|
54
55
|
window.__RAXON_API_KEY__ = apiKey;
|
|
55
56
|
window.__RAXON_API_URL__ = apiUrl;
|
|
57
|
+
window.__RAXON_STORAGE_PREFIX__ = storagePrefix;
|
|
56
58
|
nexineAxios.defaults.baseURL = apiUrl;
|
|
57
59
|
nexineAxios.defaults.headers.common["x-api-key"] = apiKey;
|
|
58
60
|
}
|
|
@@ -112,9 +114,9 @@ const RaxonProviderInner = ({ children, apiKey, apiUrl, productPathPrefix, analy
|
|
|
112
114
|
}), [normalized, isLoading, profile, authLoading, isAuthenticated, isGuest, cartState]);
|
|
113
115
|
return (_jsxs(RaxonContext.Provider, { value: value, children: [_jsx(AnalyticEventProvider, { productPathPrefix: productPathPrefix, autoTrack: analyticAutoTrack, children: children }), _jsx(ModalAuth, { ref: modalAuthRef }), _jsx(ModalNewsletterVariantProduct, { ref: modalNewsletterVariantProductRef })] }));
|
|
114
116
|
};
|
|
115
|
-
export const RaxonProvider = ({ children, apiKey, apiUrl, productPathPrefix, analyticAutoTrack, bootstrapUrl, initialBootstrapData, }) => {
|
|
117
|
+
export const RaxonProvider = ({ children, apiKey, apiUrl, storagePrefix, productPathPrefix, analyticAutoTrack, bootstrapUrl, initialBootstrapData, }) => {
|
|
116
118
|
const [queryClient] = useState(() => new QueryClient());
|
|
117
|
-
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(RaxonProviderInner, { apiKey: apiKey, apiUrl: apiUrl, productPathPrefix: productPathPrefix, analyticAutoTrack: analyticAutoTrack, bootstrapUrl: bootstrapUrl, initialBootstrapData: initialBootstrapData, children: children }) }));
|
|
119
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(RaxonProviderInner, { apiKey: apiKey, apiUrl: apiUrl, storagePrefix: storagePrefix, productPathPrefix: productPathPrefix, analyticAutoTrack: analyticAutoTrack, bootstrapUrl: bootstrapUrl, initialBootstrapData: initialBootstrapData, children: children }) }));
|
|
118
120
|
};
|
|
119
121
|
export const useRaxon = () => {
|
|
120
122
|
const context = useContext(RaxonContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nexine.axios.d.ts","sourceRoot":"","sources":["../../../core/util/nexine.axios.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nexine.axios.d.ts","sourceRoot":"","sources":["../../../core/util/nexine.axios.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,+BAMtB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { toast } from 'react-hot-toast';
|
|
3
|
+
import { getToken, removeToken } from '../util/storage.keys';
|
|
3
4
|
export const nexineAxios = axios.create({
|
|
4
5
|
baseURL: typeof window !== 'undefined' ? window.__RAXON_API_URL__ : process.env.NEXT_PUBLIC_API_URL,
|
|
5
6
|
headers: {
|
|
@@ -31,7 +32,7 @@ nexineAxios.interceptors.request.use(config => {
|
|
|
31
32
|
config.baseURL = apiUrl;
|
|
32
33
|
}
|
|
33
34
|
if (typeof window !== 'undefined') {
|
|
34
|
-
const token =
|
|
35
|
+
const token = getToken();
|
|
35
36
|
if (token) {
|
|
36
37
|
config.headers.Authorization = `Bearer ${token}`;
|
|
37
38
|
}
|
|
@@ -67,7 +68,7 @@ nexineAxios.interceptors.response.use(response => {
|
|
|
67
68
|
const requestMethod = error.config?.method || '';
|
|
68
69
|
// Token'ı temizle
|
|
69
70
|
if (typeof window !== 'undefined') {
|
|
70
|
-
|
|
71
|
+
removeToken();
|
|
71
72
|
}
|
|
72
73
|
// /auth/me endpoint'inde toast gösterme (SecurityContext yönetiyor)
|
|
73
74
|
if (!requestUrl.includes('/auth/me')) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const DEFAULT_STORAGE_PREFIX = "raxon";
|
|
2
|
+
export declare const getStoragePrefix: () => string;
|
|
3
|
+
export declare const getTokenStorageKey: () => string;
|
|
4
|
+
export declare const getTokenChangedEventName: () => string;
|
|
5
|
+
export declare const getToken: () => string | null;
|
|
6
|
+
export declare const setToken: (token: string) => void;
|
|
7
|
+
export declare const removeToken: () => void;
|
|
8
|
+
export declare const dispatchTokenChanged: () => void;
|
|
9
|
+
//# sourceMappingURL=storage.keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.keys.d.ts","sourceRoot":"","sources":["../../../core/util/storage.keys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAK9C,eAAO,MAAM,gBAAgB,QAAO,MAKnC,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,MAErC,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,MAE3C,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,MAAM,GAAG,IAGpC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,IAGxC,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,IAG9B,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,IAGvC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const DEFAULT_STORAGE_PREFIX = 'raxon';
|
|
2
|
+
const TOKEN_SUFFIX = '-token';
|
|
3
|
+
const TOKEN_CHANGED_SUFFIX = '-token-changed';
|
|
4
|
+
export const getStoragePrefix = () => {
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
return window.__RAXON_STORAGE_PREFIX__ || DEFAULT_STORAGE_PREFIX;
|
|
7
|
+
}
|
|
8
|
+
return DEFAULT_STORAGE_PREFIX;
|
|
9
|
+
};
|
|
10
|
+
export const getTokenStorageKey = () => {
|
|
11
|
+
return `${getStoragePrefix()}${TOKEN_SUFFIX}`;
|
|
12
|
+
};
|
|
13
|
+
export const getTokenChangedEventName = () => {
|
|
14
|
+
return `${getStoragePrefix()}${TOKEN_CHANGED_SUFFIX}`;
|
|
15
|
+
};
|
|
16
|
+
export const getToken = () => {
|
|
17
|
+
if (typeof window === 'undefined')
|
|
18
|
+
return null;
|
|
19
|
+
return localStorage.getItem(getTokenStorageKey());
|
|
20
|
+
};
|
|
21
|
+
export const setToken = (token) => {
|
|
22
|
+
if (typeof window === 'undefined')
|
|
23
|
+
return;
|
|
24
|
+
localStorage.setItem(getTokenStorageKey(), token);
|
|
25
|
+
};
|
|
26
|
+
export const removeToken = () => {
|
|
27
|
+
if (typeof window === 'undefined')
|
|
28
|
+
return;
|
|
29
|
+
localStorage.removeItem(getTokenStorageKey());
|
|
30
|
+
};
|
|
31
|
+
export const dispatchTokenChanged = () => {
|
|
32
|
+
if (typeof window === 'undefined')
|
|
33
|
+
return;
|
|
34
|
+
window.dispatchEvent(new Event(getTokenChangedEventName()));
|
|
35
|
+
};
|