Skip to content

Commit

Permalink
Fix/forms auth fixes (#108)
Browse files Browse the repository at this point in the history
* [KFI]feat(client-core): FormsAuthentication - fixed Logout error throwing on empty responses

* [KFI]test(client-core): FormsAuth Tests - added missing type cast

* [KFI]chore(client-core): FormsAuth - fixed error catching logic
  • Loading branch information
gallayl committed Feb 8, 2019
1 parent d3a0817 commit 19ffcd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Expand Up @@ -2,6 +2,7 @@ import { ObservableValue } from '@sensenet/client-utils'
import { User } from '@sensenet/default-content-types'
import Semaphor from 'semaphore-async-await'
import { AuthenticationService, ConstantContent, LoginState, ODataParams, ODataResponse, Repository } from '..'
import { isExtendedError } from '../Repository/Repository'

/**
* Authentication Service class for using Forms authentication through OData Actions
Expand Down Expand Up @@ -114,12 +115,19 @@ export class FormsAuthenticationService implements AuthenticationService {
* Logs out and destroys the current session
*/
public async logout(): Promise<boolean> {
await this.repository.executeAction({
method: 'POST',
idOrPath: ConstantContent.PORTAL_ROOT.Id,
name: 'Logout',
body: {},
})
try {
await this.repository.executeAction({
method: 'POST',
idOrPath: ConstantContent.PORTAL_ROOT.Id,
name: 'Logout',
body: {},
})
} catch (error) {
// ignore json parsing errors from empty response
if (!isExtendedError(error) || !error.response.ok) {
throw error
}
}
this.currentUser.setValue(ConstantContent.VISITOR_USER)
this.state.setValue(LoginState.Unauthenticated)
return true
Expand Down
2 changes: 1 addition & 1 deletion packages/sn-client-core/test/FormsAuthenticationTests.ts
Expand Up @@ -37,7 +37,7 @@ describe('Forms Authentication', () => {
const actionCall = jest.fn(async () => true)
const r = new Repository({})
r.authentication = new FormsAuthenticationService(r)
r.executeAction = actionCall
r.executeAction = actionCall as typeof r.executeAction
await r.authentication.login('username', 'password')
expect(actionCall).toBeCalledWith({
body: {
Expand Down

0 comments on commit 19ffcd1

Please sign in to comment.