Skip to main content

Authentication

This service provides helpers to handle logging out of the application.

Examples​

Logging Out​

We can log out of the application using logout. The logout process redirects the user to Gandalf for re-authentication. logout requires a returnTo parameter to specify where to forward the user once they have logged back in successfully.

import { logout } from '@rhapsody/authentication'

function logoutOnError(error?: Error) {
if (error) {
logout(window.location.href)
}
}

Register Before-logout Callbacks​

If we need execute any code prior to logging out, e.g. sending a message to the Chrome extension, we can use registerBeforeLogoutCallback to register a before-logout callback that will be executed synchronously before the user is redirected to Gandalf. registerBeforeLogoutCallback returns a function that can be used to remove the registered callback.

import { registerBeforeLogoutCallback } from '@rhapsody/authentication'

const unregister = registerBeforeLogoutCallback(() => {
console.log('About to log out.')
})

// ...

unregister()