File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 44 "type" : " git" ,
55 "url" : " https://github.com/PropelAuth/javascript"
66 },
7- "version" : " 1.1.0 " ,
7+ "version" : " 1.1.1 " ,
88 "keywords" : [
99 " auth" ,
1010 " user" ,
Original file line number Diff line number Diff line change 11import { AuthenticationInfo , fetchAuthenticationInfo , logout } from "./api"
2- import { currentTimeSeconds , getLocalStorageNumber } from "./helpers"
2+ import { currentTimeSeconds , getLocalStorageNumber , hasLocalStorage } from "./helpers"
33
44const LOGGED_IN_AT_KEY = "__PROPEL_AUTH_LOGGED_IN_AT"
55const LOGGED_OUT_AT_KEY = "__PROPEL_AUTH_LOGGED_OUT_AT"
@@ -268,6 +268,12 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
268268 }
269269
270270 const onStorageChange = async function ( ) {
271+ // If localStorage isn't available, nothing to do here.
272+ // This usually happens in frameworks that have some SSR components
273+ if ( ! hasLocalStorage ( ) ) {
274+ return
275+ }
276+
271277 const loggedOutAt = getLocalStorageNumber ( LOGGED_OUT_AT_KEY )
272278 const loggedInAt = getLocalStorageNumber ( LOGGED_IN_AT_KEY )
273279
Original file line number Diff line number Diff line change @@ -2,7 +2,15 @@ export function currentTimeSeconds() {
22 return Date . now ( ) / 1000
33}
44
5+ export function hasLocalStorage ( ) : boolean {
6+ return typeof localStorage !== 'undefined'
7+ }
8+
59export function getLocalStorageNumber ( key : string ) : number | null {
10+ if ( ! hasLocalStorage ( ) ) {
11+ return null ;
12+ }
13+
614 const value = localStorage . getItem ( key )
715 if ( ! value ) {
816 return null
You can’t perform that action at this time.
0 commit comments