From a7c282ca348c1e8e60559e5c064caee28ba11eec Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>
Date: Wed, 9 Oct 2024 16:34:12 +0300
Subject: refactor: so much shit

---
 frontend/src/utils/Jwt.tsx | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 frontend/src/utils/Jwt.tsx

(limited to 'frontend/src/utils/Jwt.tsx')

diff --git a/frontend/src/utils/Jwt.tsx b/frontend/src/utils/Jwt.tsx
new file mode 100644
index 0000000..ce351fb
--- /dev/null
+++ b/frontend/src/utils/Jwt.tsx
@@ -0,0 +1,44 @@
+// llm ahh funcs
+export function get_user_id_from_token(token: string | undefined): string | undefined {
+  if (!token) {
+    return undefined;
+  }
+  const parts = token.split('.');
+  if (parts.length !== 3) {
+    return undefined;
+  }
+  const base64Url = parts[1];
+  const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
+
+  const jsonPayload = decodeURIComponent(
+    atob(base64)
+      .split('')
+      .map(function (c) {
+        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+      })
+      .join('')
+  );
+  return JSON.parse(jsonPayload).sub;
+};
+
+export function get_user_mod_from_token(token: string | undefined): boolean | undefined {
+  if (!token) {
+    return undefined;
+  }
+  const parts = token.split('.');
+  if (parts.length !== 3) {
+    return undefined;
+  }
+  const base64Url = parts[1];
+  const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
+
+  const jsonPayload = decodeURIComponent(
+    atob(base64)
+      .split('')
+      .map(function (c) {
+        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+      })
+      .join('')
+  );
+  return JSON.parse(jsonPayload).mod;
+};
-- 
cgit v1.2.3

