|
|
@@ -19,13 +19,13 @@ class Authenticator {
|
|
19
|
19
|
return await db.post('/user/token', req, true)
|
|
20
|
20
|
}
|
|
21
|
21
|
/** Check if session still active in backend */
|
|
22
|
|
- async #isValidSession() {
|
|
23
|
|
- const hash = this.#getHashedToken()
|
|
|
22
|
+ async isValidSession() {
|
|
|
23
|
+ const hash = this.getHashedToken()
|
|
24
|
24
|
let validation
|
|
25
|
25
|
try {
|
|
26
|
26
|
validation = await db.post('/user/validate-session', hash, true)
|
|
27
|
27
|
} catch (error) {
|
|
28
|
|
- console.error(error)
|
|
|
28
|
+ console.error(`Invalid session: ${error}`)
|
|
29
|
29
|
}
|
|
30
|
30
|
console.log('valid Session :>> ', validation)
|
|
31
|
31
|
return validation
|
|
|
@@ -34,10 +34,10 @@ class Authenticator {
|
|
34
|
34
|
return await db.post('/user/login', credentials)
|
|
35
|
35
|
}
|
|
36
|
36
|
async removeSession() {
|
|
37
|
|
- const hash = this.#getHashedToken()
|
|
|
37
|
+ const hash = this.getHashedToken()
|
|
38
|
38
|
return await db.post('/user/remove-session', hash, true)
|
|
39
|
39
|
}
|
|
40
|
|
- #getHashedToken(cookieKey = 'siimee_session') {
|
|
|
40
|
+ getHashedToken(cookieKey = 'siimee_session') {
|
|
41
|
41
|
const cookies = document.cookie.split('; ').reduce((prev, current) => {
|
|
42
|
42
|
const [name, ...value] = current.split('=')
|
|
43
|
43
|
prev[name] = value.join('=')
|
|
|
@@ -49,12 +49,6 @@ class Authenticator {
|
|
49
|
49
|
)
|
|
50
|
50
|
return cookies[cookieKey]
|
|
51
|
51
|
}
|
|
52
|
|
- async checkSessionValid() {
|
|
53
|
|
- const validation = await this.#isValidSession()
|
|
54
|
|
- if (validation.error)
|
|
55
|
|
- return console.error('ERROR :=>', validation.error)
|
|
56
|
|
- return validation
|
|
57
|
|
- }
|
|
58
|
52
|
}
|
|
59
|
53
|
const authenticator = new Authenticator()
|
|
60
|
54
|
|