Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/forms auth fixes #108

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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