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 11{
22 "name" : " jsorm" ,
3- "version" : " 0.4.1 " ,
3+ "version" : " 0.5.0 " ,
44 "description" : " Javascript ORM" ,
55 "main" : " _bundles/jsorm.js" ,
66 "module" : " lib-esm/index.js" ,
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ export default class Model {
6363
6464 static setJWT ( token : string ) : void {
6565 this . getJWTOwner ( ) . jwt = token ;
66+
67+ if ( Config . jwtLocalStorage ) {
68+ Config . localStorage . setItem ( Config . jwtLocalStorage , token )
69+ }
6670 }
6771
6872 static getJWT ( ) : string {
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ import Config from '../configuration';
33
44export default function refreshJWT ( klass : typeof Model , serverResponse : Response ) : void {
55 let jwt = serverResponse . headers . get ( 'X-JWT' ) ;
6- let localStorage = Config . localStorage ;
6+ if ( ! jwt ) return
77
8+ let localStorage = Config . localStorage ;
89 if ( localStorage ) {
910 let localStorageKey = Config . jwtLocalStorage ;
1011 if ( localStorageKey ) {
Original file line number Diff line number Diff line change @@ -132,6 +132,25 @@ describe('Model', function() {
132132 Author . setJWT ( 'n3wt0k3n' ) ;
133133 expect ( ApplicationRecord . jwt ) . to . eq ( 'n3wt0k3n' ) ;
134134 } ) ;
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+ } )
135154 } ) ;
136155
137156 describe ( '#fetchOptions' , function ( ) {
You can’t perform that action at this time.
0 commit comments