File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " jsorm" ,
3
- "version" : " 0.4.1 " ,
3
+ "version" : " 0.5.0 " ,
4
4
"description" : " Javascript ORM" ,
5
5
"main" : " _bundles/jsorm.js" ,
6
6
"module" : " lib-esm/index.js" ,
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ export default class Model {
63
63
64
64
static setJWT ( token : string ) : void {
65
65
this . getJWTOwner ( ) . jwt = token ;
66
+
67
+ if ( Config . jwtLocalStorage ) {
68
+ Config . localStorage . setItem ( Config . jwtLocalStorage , token )
69
+ }
66
70
}
67
71
68
72
static getJWT ( ) : string {
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ import Config from '../configuration';
3
3
4
4
export default function refreshJWT ( klass : typeof Model , serverResponse : Response ) : void {
5
5
let jwt = serverResponse . headers . get ( 'X-JWT' ) ;
6
- let localStorage = Config . localStorage ;
6
+ if ( ! jwt ) return
7
7
8
+ let localStorage = Config . localStorage ;
8
9
if ( localStorage ) {
9
10
let localStorageKey = Config . jwtLocalStorage ;
10
11
if ( localStorageKey ) {
Original file line number Diff line number Diff line change @@ -132,6 +132,25 @@ describe('Model', function() {
132
132
Author . setJWT ( 'n3wt0k3n' ) ;
133
133
expect ( ApplicationRecord . jwt ) . to . eq ( 'n3wt0k3n' ) ;
134
134
} ) ;
135
+
136
+ describe . only ( 'when localStorage is configured' , function ( ) {
137
+ beforeEach ( function ( ) {
138
+ Config . jwtLocalStorage = 'jwt'
139
+ Config . localStorage = { setItem : sinon . spy ( ) }
140
+ } )
141
+
142
+ afterEach ( function ( ) {
143
+ Config . jwtLocalStorage = undefined
144
+ Config . localStorage = undefined
145
+ } )
146
+
147
+ it ( 'adds to localStorage' , function ( ) {
148
+ Author . setJWT ( 'n3wt0k3n' ) ;
149
+ let called = Config . localStorage . setItem
150
+ . calledWith ( 'jwt' , 'n3wt0k3n' ) ;
151
+ expect ( called ) . to . eq ( true ) ;
152
+ } )
153
+ } )
135
154
} ) ;
136
155
137
156
describe ( '#fetchOptions' , function ( ) {
You can’t perform that action at this time.
0 commit comments