Skip to content

Commit 47714dd

Browse files
Merge pull request #824 from supertokens/fix/remove-sdk-logs
Chore: Remove sdk logs
2 parents efe931c + 937000c commit 47714dd

File tree

7 files changed

+283
-221
lines changed

7 files changed

+283
-221
lines changed

v2/src/components/customAdmonition/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function CustomAdmonition(props: PropsWithChildren<{
1919
<h5>
2020
<span className="admonition-icon">
2121
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
22-
<path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path>
22+
<path fillRule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path>
2323
</svg>
2424
</span>
2525
{allowedTypes[props.type]}

v2/src/components/httpNetworking.ts

Lines changed: 17 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from "axios";
2-
import { getAnalytics, sendSDKLogsToBackend } from "./utils";
3-
import { getUserInformation } from "./api/user/info";
2+
import { getHttpNetworkingSDKLogsHooks } from "./sdklogsutils";
43

54
export enum HTTP_REQUEST_ERROR {
65
SESSION_EXPIRED,
@@ -102,11 +101,12 @@ export async function simpleGETRequest(url: string, userConfig: any = {}, versio
102101
"api-version": version + ""
103102
}
104103
};
105-
let frontTokenExists = cookieExists("sFrontToken");
104+
const sdkLogsHooks = getHttpNetworkingSDKLogsHooks();
105+
sdkLogsHooks.preApiExecutionHook();
106106
let response = await axios.get(url, userConfig);
107107
let data = await response.data;
108108
let headers = response.headers;
109-
await sendAnalyticsIfFrontTokenRemoved(url, frontTokenExists, headers);
109+
sdkLogsHooks.postApiExecutionHook(url, headers);
110110
return { data, headers };
111111
}
112112

@@ -122,11 +122,12 @@ export async function simplePOSTRequest(url: string, data: any, userConfig: POST
122122
"api-version": version + ""
123123
}
124124
};
125-
let frontTokenExists = cookieExists("sFrontToken");
125+
const sdkLogsHooks = getHttpNetworkingSDKLogsHooks();
126+
sdkLogsHooks.preApiExecutionHook();
126127
let response = await axios.post(url, data, userConfig);
127128
let responseData = response.data;
128129
let headers = response.headers;
129-
await sendAnalyticsIfFrontTokenRemoved(url, frontTokenExists, headers);
130+
sdkLogsHooks.postApiExecutionHook(url, headers);
130131
return { data: responseData, headers, status: response.status, statusText: response.statusText };
131132
}
132133

@@ -142,11 +143,12 @@ export async function simplePATCHRequest(url: string, data: any, userConfig: PAT
142143
"api-version": version + ""
143144
}
144145
};
145-
let frontTokenExists = cookieExists("sFrontToken");
146+
const sdkLogsHooks = getHttpNetworkingSDKLogsHooks();
147+
sdkLogsHooks.preApiExecutionHook();
146148
let response = await axios.patch(url, data, userConfig);
147149
let responseData = response.data;
148150
let headers = response.headers;
149-
await sendAnalyticsIfFrontTokenRemoved(url, frontTokenExists, headers);
151+
sdkLogsHooks.postApiExecutionHook(url, headers);
150152
return { data: responseData, headers };
151153
}
152154

@@ -162,11 +164,12 @@ export async function simplePUTRequest(url: string, data: any, userConfig: POSTR
162164
"api-version": version + ""
163165
}
164166
};
165-
let frontTokenExists = cookieExists("sFrontToken");
167+
const sdkLogsHooks = getHttpNetworkingSDKLogsHooks();
168+
sdkLogsHooks.preApiExecutionHook();
166169
let response = await axios.put(url, data, userConfig);
167170
let responseData = response.data;
168171
let headers = response.headers;
169-
await sendAnalyticsIfFrontTokenRemoved(url, frontTokenExists, headers);
172+
sdkLogsHooks.postApiExecutionHook(url, headers);
170173
return { data: responseData, headers };
171174
}
172175

@@ -185,132 +188,12 @@ export async function simpleDELETERequest(url: string, userConfig: DELETERequest
185188
"api-version": version + ""
186189
}
187190
};
188-
let frontTokenExists = cookieExists("sFrontToken");
191+
const sdkLogsHooks = getHttpNetworkingSDKLogsHooks();
192+
sdkLogsHooks.preApiExecutionHook();
189193
delete userConfig.params;
190194
let response = await axios.delete(url, userConfig);
191195
let data = await response.data;
192196
let headers = response.headers;
193-
await sendAnalyticsIfFrontTokenRemoved(url, frontTokenExists, headers);
197+
sdkLogsHooks.postApiExecutionHook(url, headers);
194198
return { data, headers };
195-
}
196-
197-
async function sendAnalyticsIfFrontTokenRemoved(url: string, frontTokenExists: boolean, headers: any) {
198-
if (!frontTokenExists) {
199-
return;
200-
}
201-
let updatedFrontTokenExists = cookieExists("sFrontToken");
202-
if (!updatedFrontTokenExists) {
203-
// this means it was removed between the api call!
204-
// send analytics
205-
sendAuthAnalytics("front_token_removed", {
206-
url,
207-
headers
208-
});
209-
await sendSDKLogsToBackend()
210-
}
211-
}
212-
213-
export function cookieExists(name: string) {
214-
const cookies = document.cookie;
215-
const regex = new RegExp("(^|; )" + encodeURIComponent(name) + "=");
216-
return regex.test(cookies);
217-
}
218-
219-
const sendAuthAnalytics = (eventName: string, payload: Record<string, unknown>, version = "v1") => {
220-
getAnalytics().then((stAnalytics: any) => {
221-
if (stAnalytics === undefined) {
222-
console.log("mocked event send:", eventName, version, payload);
223-
return;
224-
}
225-
stAnalytics.sendEvent(
226-
eventName,
227-
{
228-
type: "auth",
229-
...payload
230-
},
231-
version
232-
);
233-
});
234-
};
235-
236-
function getCookieValue(cookieName: string) {
237-
const cookies = document.cookie;
238-
const cookieArray = cookies.split(';');
239-
for (let i = 0; i < cookieArray.length; i++) {
240-
const cookie = cookieArray[i].trim();
241-
if (cookie.startsWith(cookieName + '=')) {
242-
return cookie.substring(cookieName.length + 1);
243-
}
244-
}
245-
return null;
246-
}
247-
248-
export async function checkForDesyncedSession() {
249-
const EVENT_NAME = 'desynced_session_state';
250-
const didFrontTokenExistBeforeAPICall = cookieExists("sFrontToken");
251-
252-
try {
253-
await getUserInformation();
254-
const doesFrontendTokenExistAfterAPICall = cookieExists("sFrontToken");
255-
if (!doesFrontendTokenExistAfterAPICall) {
256-
const payload = {
257-
didFrontTokenExistBeforeAPICall,
258-
stLastAccessTokenUpdate: getCookieValue("st-last-access-token-update"),
259-
statusCode: 200
260-
};
261-
getAnalytics().then((stAnalytics: any) => {
262-
if (stAnalytics === undefined) {
263-
console.log('mocked event send:', EVENT_NAME, 'v1', payload);
264-
return;
265-
}
266-
stAnalytics.sendEvent(
267-
EVENT_NAME,
268-
{
269-
type: EVENT_NAME,
270-
...payload,
271-
},
272-
'v1'
273-
);
274-
});
275-
}
276-
} catch (e:any) {
277-
if (
278-
"response" in e &&
279-
e.response.status === 401 &&
280-
e.response.data &&
281-
e.response.data.message === "try refresh token"
282-
) {
283-
if (!cookieExists("sFrontToken")) {
284-
const payload = {
285-
didFrontTokenExistBeforeAPICall,
286-
stLastAccessTokenUpdate: getCookieValue("st-last-access-token-update"),
287-
statusCode: 401
288-
};
289-
getAnalytics().then((stAnalytics: any) => {
290-
if (stAnalytics === undefined) {
291-
console.log("mocked event send:", EVENT_NAME, "v1", payload);
292-
return;
293-
}
294-
stAnalytics.sendEvent(
295-
EVENT_NAME,
296-
{
297-
type: EVENT_NAME,
298-
...payload
299-
},
300-
"v1"
301-
);
302-
});
303-
}
304-
}
305-
}
306-
}
307-
308-
export function historyPushStateOverride(onPush: () => void) {
309-
const originalPushState = history.pushState;
310-
history.pushState = function (...args) {
311-
const result = originalPushState.apply(this, args);
312-
onPush();
313-
return result;
314-
};
315-
}
316-
199+
}

0 commit comments

Comments
 (0)