mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-12 02:21:06 +03:30
53 lines
1.1 KiB
JavaScript
Vendored
53 lines
1.1 KiB
JavaScript
Vendored
import qs from 'qs';
|
|
|
|
const TOKEN_KEY = 'access_token'
|
|
const REFRESH_TOKEN_KEY = 'refresh_token'
|
|
const INFO = 'info'
|
|
/**
|
|
* Manage the how Access Tokens are being stored and retreived from storage.
|
|
*
|
|
* Current implementation stores to localStorage. Local Storage should always be
|
|
* accessed through this instace.
|
|
**/
|
|
const TokenService = {
|
|
getToken() {
|
|
return localStorage.getItem(TOKEN_KEY)
|
|
},
|
|
|
|
saveToken(accessToken = null) {
|
|
localStorage.setItem(TOKEN_KEY, accessToken)
|
|
},
|
|
|
|
removeToken() {
|
|
localStorage.removeItem(TOKEN_KEY)
|
|
},
|
|
|
|
getRefreshToken() {
|
|
return localStorage.getItem(REFRESH_TOKEN_KEY)
|
|
},
|
|
|
|
saveRefreshToken(refreshToken = null) {
|
|
localStorage.setItem(REFRESH_TOKEN_KEY, refreshToken)
|
|
},
|
|
|
|
removeRefreshToken() {
|
|
localStorage.removeItem(REFRESH_TOKEN_KEY)
|
|
},
|
|
|
|
getInfo() {
|
|
return qs.parse(localStorage.getItem(INFO))
|
|
},
|
|
|
|
saveInfo(info = null) {
|
|
info = qs.stringify(info);
|
|
localStorage.setItem(INFO, info)
|
|
},
|
|
|
|
removeInfo() {
|
|
localStorage.removeItem(INFO)
|
|
},
|
|
|
|
}
|
|
|
|
export { TokenService }
|