- const accessTokenLocalStorage = localStorage.getItem(this.KEYS.ACCESS_TOKEN)
- const refreshTokenLocalStorage = localStorage.getItem(this.KEYS.REFRESH_TOKEN)
- const tokenTypeLocalStorage = localStorage.getItem(this.KEYS.TOKEN_TYPE)
-
- if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) {
- return new Tokens({
- accessToken: accessTokenLocalStorage,
- refreshToken: refreshTokenLocalStorage,
- tokenType: tokenTypeLocalStorage
- })
- }
-
- return null
- }
-
- static flush () {
- localStorage.removeItem(this.KEYS.ACCESS_TOKEN)
- localStorage.removeItem(this.KEYS.REFRESH_TOKEN)
- localStorage.removeItem(this.KEYS.TOKEN_TYPE)
- }
-
- constructor (hash?: TokenOptions) {
- if (hash) {
- this.accessToken = hash.accessToken
- this.refreshToken = hash.refreshToken
-
- if (hash.tokenType === 'bearer') {
- this.tokenType = 'Bearer'
- } else {
- this.tokenType = hash.tokenType
- }
- }
- }