Преглед изворни кода

: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
     async createToken(req) {
18
     async createToken(req) {
19
         return await db.post('/user/token', req, true)
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
         let validation
24
         let validation
25
         try {
25
         try {
26
             validation = await db.post(
26
             validation = await db.post(
27
                 '/user/validate-session',
27
                 '/user/validate-session',
28
-                hashedSessionToken,
28
+                hash,
29
                 true,
29
                 true,
30
             )
30
             )
31
         } catch (error) {
31
         } catch (error) {
32
             console.error(error)
32
             console.error(error)
33
         }
33
         }
34
-        console.log('validatedSession :>> ', validation)
34
+        console.log('valid Session :>> ', validation)
35
         return validation
35
         return validation
36
     }
36
     }
37
     async authenticateLoginCredentials(credentials) {
37
     async authenticateLoginCredentials(credentials) {
38
         return await db.post('/user/login', credentials)
38
         return await db.post('/user/login', credentials)
39
     }
39
     }
40
     async removeSession() {
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
         const cookies = document.cookie.split('; ').reduce((prev, current) => {
45
         const cookies = document.cookie.split('; ').reduce((prev, current) => {
46
             const [name, ...value] = current.split('=')
46
             const [name, ...value] = current.split('=')
47
             prev[name] = value.join('=')
47
             prev[name] = value.join('=')
54
         return cookies[cookieKey]
54
         return cookies[cookieKey]
55
     }
55
     }
56
     async checkSessionValid() {
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
 const authenticator = new Authenticator()
63
 const authenticator = new Authenticator()

Loading…
Откажи
Сачувај