Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
67ccfb08
Commit
67ccfb08
authored
May 17, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
May 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more strict return type on LocalStorageService.getObject
parent
4645088e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
7 deletions
+13
-7
auth.ts
src/sidebar/services/auth.ts
+11
-6
local-storage.ts
src/sidebar/services/local-storage.ts
+1
-1
tags.js
src/sidebar/services/tags.js
+1
-0
No files found.
src/sidebar/services/auth.ts
View file @
67ccfb08
...
...
@@ -14,6 +14,16 @@ type RefreshOptions = {
persist
:
boolean
;
};
const
isTokenInfo
=
(
token
:
unknown
):
token
is
TokenInfo
=>
!!
token
&&
typeof
token
===
'object'
&&
'accessToken'
in
token
&&
typeof
token
.
accessToken
===
'string'
&&
'refreshToken'
in
token
&&
typeof
token
.
refreshToken
===
'string'
&&
'expiresAt'
in
token
&&
typeof
token
.
expiresAt
===
'number'
;
/**
* Authorization service.
*
...
...
@@ -96,12 +106,7 @@ export class AuthService extends TinyEmitter {
private
_loadToken
()
{
const
token
=
this
.
_localStorage
.
getObject
(
this
.
_storageKey
());
if
(
!
token
||
typeof
token
.
accessToken
!==
'string'
||
typeof
token
.
refreshToken
!==
'string'
||
typeof
token
.
expiresAt
!==
'number'
)
{
if
(
!
isTokenInfo
(
token
))
{
return
null
;
}
...
...
src/sidebar/services/local-storage.ts
View file @
67ccfb08
...
...
@@ -59,7 +59,7 @@ export class LocalStorageService {
/**
* Look up and deserialize a value from storage.
*/
getObject
<
T
=
any
>
(
key
:
string
):
T
|
null
{
getObject
<
T
=
unknown
>
(
key
:
string
):
T
|
null
{
const
item
=
this
.
_storage
.
getItem
(
key
);
return
item
?
(
JSON
.
parse
(
item
)
as
T
)
:
null
;
}
...
...
src/sidebar/services/tags.js
View file @
67ccfb08
...
...
@@ -67,6 +67,7 @@ export class TagsService {
*/
store
(
tags
)
{
// Update the stored (tag, frequency) map.
/** @type Record<string, { text: string; count: number; updated: number }> */
const
savedTags
=
this
.
_storage
.
getObject
(
TAGS_MAP_KEY
)
||
{};
tags
.
forEach
(
tag
=>
{
if
(
savedTags
[
tag
])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment