瀏覽代碼

:recycle: tweaking names

neo
toj 2 年之前
父節點
當前提交
f1a317dad2
共有 1 個檔案被更改,包括 12 行新增12 行删除
  1. 12
    12
      frontend/src/services/auth.service.js

+ 12
- 12
frontend/src/services/auth.service.js 查看文件

@@ -18,30 +18,30 @@ class Authenticator {
18 18
     async createToken(req) {
19 19
         return await db.post('/user/token', req, true)
20 20
     }
21
-    /** Check for session existence in backend */
22
-    async #validateSession() {
23
-        const hashedSessionToken = this.grabStoredSessionToken()
21
+    /** Check if session still active in backend */
22
+    async #isValidSession() {
23
+        const hash = this.#getHashedToken()
24 24
         let validation
25 25
         try {
26 26
             validation = await db.post(
27 27
                 '/user/validate-session',
28
-                hashedSessionToken,
28
+                hash,
29 29
                 true,
30 30
             )
31 31
         } catch (error) {
32 32
             console.error(error)
33 33
         }
34
-        console.log('validatedSession :>> ', validation)
34
+        console.log('valid Session :>> ', validation)
35 35
         return validation
36 36
     }
37 37
     async authenticateLoginCredentials(credentials) {
38 38
         return await db.post('/user/login', credentials)
39 39
     }
40 40
     async removeSession() {
41
-        const hashedSessionToken = this.grabStoredSessionToken()
42
-        return await db.post('/user/remove-session', hashedSessionToken, true)
41
+        const hash = this.#getHashedToken()
42
+        return await db.post('/user/remove-session', hash, true)
43 43
     }
44
-    grabStoredSessionToken(cookieKey = 'siimee_session') {
44
+    #getHashedToken(cookieKey = 'siimee_session') {
45 45
         const cookies = document.cookie.split('; ').reduce((prev, current) => {
46 46
             const [name, ...value] = current.split('=')
47 47
             prev[name] = value.join('=')
@@ -54,10 +54,10 @@ class Authenticator {
54 54
         return cookies[cookieKey]
55 55
     }
56 56
     async checkSessionValid() {
57
-        const validatedToken = await this.#validateSession()
58
-        if (validatedToken.error)
59
-            return console.error('ERROR :=>', validatedToken.error)
60
-        return validatedToken
57
+        const validation = await this.#isValidSession()
58
+        if (validation.error)
59
+            return console.error('ERROR :=>', validation.error)
60
+        return validation
61 61
     }
62 62
 }
63 63
 const authenticator = new Authenticator()

Loading…
取消
儲存