summaryrefslogtreecommitdiff
path: root/app/lib/api/clearOdooSession.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/api/clearOdooSession.ts')
-rw-r--r--app/lib/api/clearOdooSession.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/lib/api/clearOdooSession.ts b/app/lib/api/clearOdooSession.ts
new file mode 100644
index 0000000..0ad9a5d
--- /dev/null
+++ b/app/lib/api/clearOdooSession.ts
@@ -0,0 +1,25 @@
+export async function clearOdooSession(baseUrl: string) {
+ try {
+ if (baseUrl) {
+ await fetch(`${baseUrl}/web/session/destroy`, {
+ method: "POST",
+ credentials: "include",
+ headers: { "Content-Type": "application/json" },
+ body: "{}",
+ });
+ }
+ } catch { }
+
+ // 2) hapus cookie session_id di browser
+ try {
+ const del = (name: string, domain?: string) => {
+ const d = domain ? `; domain=${domain}` : "";
+ document.cookie = `${name}=; Max-Age=0; Path=/${d}`;
+ document.cookie = `${name}=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/${d}`;
+ };
+ const host = window.location.hostname.replace(/^www\./, "");
+ const parts = host.split(".");
+ const parent = parts.length >= 2 ? `.${parts.slice(-2).join(".")}` : undefined;
+ [undefined, host, parent].forEach(dom => del("session_id", dom));
+ } catch { }
+}