File tree Expand file tree Collapse file tree
packages/authentication-client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -166,14 +166,20 @@ export class AuthenticationClient {
166166
167167 logout ( ) {
168168 return Promise . resolve ( this . app . get ( 'authentication' ) )
169- . then ( ( ) => this . service . remove ( null ) )
170- . then ( ( authResult : AuthenticationResult ) => this . removeAccessToken ( )
171- . then ( ( ) => this . reset ( ) )
172- . then ( ( ) => {
173- this . app . emit ( 'logout' , authResult ) ;
174-
175- return authResult ;
176- } )
177- ) ;
169+ . then ( auth => {
170+ if ( ! auth ) {
171+ return null ;
172+ }
173+
174+ return this . service . remove ( null )
175+ . then ( ( authResult : AuthenticationResult ) => this . removeAccessToken ( )
176+ . then ( ( ) => this . reset ( ) )
177+ . then ( ( ) => {
178+ this . app . emit ( 'logout' , authResult ) ;
179+
180+ return authResult ;
181+ } )
182+ ) ;
183+ } ) ;
178184 }
179185}
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ describe('@feathersjs/authentication-client', () => {
2424 } ,
2525
2626 remove ( id ) {
27+ if ( ! app . get ( 'authentication' ) ) {
28+ throw new Error ( 'Not logged in' ) ;
29+ }
30+
2731 return Promise . resolve ( { id } ) ;
2832 }
2933 } ) ;
@@ -131,6 +135,12 @@ describe('@feathersjs/authentication-client', () => {
131135 } ) ;
132136 } ) ;
133137
138+ it ( 'logout when not logged in without error' , async ( ) => {
139+ const result = await app . logout ( ) ;
140+
141+ assert . strictEqual ( result , null ) ;
142+ } ) ;
143+
134144 describe ( 'reauthenticate' , ( ) => {
135145 it ( 'fails when no token in storage' , ( ) => {
136146 return app . authentication . reAuthenticate ( ) . then ( ( ) => {
You can’t perform that action at this time.
0 commit comments