@@ -25,17 +25,6 @@ import {WSDropdown} from '../ws-dropdown/ws-dropdown';
25
25
*/
26
26
export class WSHeader extends Component {
27
27
28
- /**
29
- * @type {Authorization }
30
- */
31
- static authorization = undefined ;
32
-
33
- /**
34
- * Default storage instance
35
- * @type {AbstractStorage }
36
- */
37
- static storage = new LocalStorage ( ) ;
38
-
39
28
static defaultProps = {
40
29
loginUrl : 'https://identity.zalando.com/oauth2/authorize' ,
41
30
businessPartnerId : null ,
@@ -64,6 +53,17 @@ export class WSHeader extends Component {
64
53
showAuthorization : PropTypes . bool
65
54
} ;
66
55
56
+ /**
57
+ * @type {Authorization }
58
+ */
59
+ static authorization = new Authorization ( this . storage ) ;
60
+
61
+ /**
62
+ * Default storage instance
63
+ * @type {AbstractStorage }
64
+ */
65
+ static storage = new LocalStorage ( '' ) ;
66
+
67
67
/**
68
68
* Initialize the storage
69
69
* @param {string } type Can be either cookie or local
@@ -77,6 +77,8 @@ export class WSHeader extends Component {
77
77
} else {
78
78
this . storage = new LocalStorage ( name ) ;
79
79
}
80
+ // Create authorization with new storage type
81
+ this . authorization . storage = this . storage ;
80
82
}
81
83
82
84
/**
@@ -85,7 +87,6 @@ export class WSHeader extends Component {
85
87
* @returns {string|null }
86
88
*/
87
89
static getAccessToken ( queryString = location . hash . substr ( 1 ) ) {
88
- this . authorization = this . authorization || new Authorization ( this . storage ) ;
89
90
if ( ! this . authorization . accessToken ) {
90
91
this . authorization . tryFetchToken ( queryString ) ;
91
92
}
@@ -97,7 +98,6 @@ export class WSHeader extends Component {
97
98
* @returns {void }
98
99
*/
99
100
static removeAccessToken ( ) {
100
- this . authorization = this . authorization || new Authorization ( this . storage ) ;
101
101
this . authorization . unauthorize ( ) ;
102
102
}
103
103
@@ -176,7 +176,7 @@ export class WSHeader extends Component {
176
176
*/
177
177
initState ( ) {
178
178
this . state = {
179
- isLoggedIn : ! ! ( this . constructor . authorization && this . constructor . authorization . accessToken ) ,
179
+ isLoggedIn : ! ! this . constructor . authorization . accessToken ,
180
180
locale : WSHeader . getLocale ( )
181
181
} ;
182
182
}
@@ -186,8 +186,6 @@ export class WSHeader extends Component {
186
186
* @returns {void }
187
187
*/
188
188
initAuthorization ( ) {
189
- // Initialize authorization with implicit flow
190
- this . constructor . authorization = this . constructor . authorization || new Authorization ( WSHeader . storage ) ;
191
189
// Listen to authorization changes
192
190
this . constructor . authorization . onAccessTokenChange ( accessToken => {
193
191
if ( this . mounted ) {
0 commit comments