File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
packages/blitz-auth/src/client Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @blitzjs/auth " : minor
3
+ ---
4
+
5
+ fix failed localStorage access to not crash the application
Original file line number Diff line number Diff line change @@ -90,7 +90,11 @@ class PublicDataStore {
90
90
91
91
clear ( ) {
92
92
deleteCookie ( COOKIE_PUBLIC_DATA_TOKEN ( ) )
93
- localStorage . removeItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) )
93
+ try {
94
+ localStorage . removeItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) )
95
+ } catch ( err ) {
96
+ console . error ( "LocalStorage is not available" , err )
97
+ }
94
98
this . updateState ( emptyPublicData )
95
99
}
96
100
@@ -105,12 +109,17 @@ class PublicDataStore {
105
109
}
106
110
107
111
private getToken ( ) {
108
- const cookieValue = readCookie ( COOKIE_PUBLIC_DATA_TOKEN ( ) )
109
- if ( cookieValue ) {
110
- localStorage . setItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) , cookieValue )
111
- return cookieValue
112
- } else {
113
- return localStorage . getItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) )
112
+ try {
113
+ const cookieValue = readCookie ( COOKIE_PUBLIC_DATA_TOKEN ( ) )
114
+ if ( cookieValue ) {
115
+ localStorage . setItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) , cookieValue )
116
+ return cookieValue
117
+ } else {
118
+ return localStorage . getItem ( LOCALSTORAGE_PUBLIC_DATA_TOKEN ( ) )
119
+ }
120
+ } catch ( err ) {
121
+ console . error ( "LocalStorage is not available" , err )
122
+ return undefined
114
123
}
115
124
}
116
125
}
You can’t perform that action at this time.
0 commit comments